$firstname = "Peter";
$lastname = "Griffin";
$age = "41";
$result = compact("firstname", "lastname", "age");
print_r($result);
$errors->has('accountable_id') did not work @if($errors->has('accountable_id'))
<div class="invalid-feedback">
<strong>{{ $errors->first('accountable_id') }}</strong>
</div>
@endifUntil is-invalid class was specifiedclass="form-control {{ $errors->has('accountable_id') ? 'is-invalid' : '' }}"
The complete example<div class="form-group">
<label for="exampleSelect2">Accountable <span class="text-danger">*</span></label>
<select class="form-control {{ $errors->has('accountable_id') ? 'is-invalid' : '' }}" id="accountable_id" name="accountable_id">
<option value="">Select Accountable</option>
@foreach($users as $accountable)
<option value="{{ $accountable->id }}" {{ $accountable_id == $accountable->id ? 'selected' : '' }}>{{ $accountable->name }}</option>
@endforeach
</select>
@if($errors->has('accountable_id'))
<div class="invalid-feedback">
<strong>{{ $errors->first('accountable_id') }}</strong>
</div>
@endif
</div>blade file on each row@if ($errors->any())
@foreach ($errors->all() as $error)
<div>{{$error}}</div>
@endforeach
@endifcreated_at column. You will pass the column name that you wish to sort by using orderBy method.
new method latest() eloquent
public function getLatestRecord()
{
$latests = User::latest()->get();
}
old method OrderBy with latest eloquent
public function getLatestRecord()
{
$latests = \DB::table('users')->orderBy('created_at','desc')->get();
}
new method oldest() eloquent
public function getOldestRecord()
{
$oldest = User::oldest()->get();
}deleted_at attribute is set on the model indicating the date and time at which the model was "deleted". To enable soft deletes for a model, add the Illuminate\Database\Eloquent\SoftDeletes trait to the model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Flight extends Model
{
use SoftDeletes;
}
You should also add the deleted_at column to your database table. The Laravel schema builder contains a helper method to create this column:
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Facades\Schema;
Schema::table('flights', function (Blueprint $table) {
$table->softDeletes();
});
Schema::table('flights', function (Blueprint $table) {
$table->dropSoftDeletes();
});
Now, when you call the delete method on the model, the deleted_at column will be set to the current date and time. However, the model's database record will be left in the table. When querying a model that uses soft deletes, the soft deleted models will automatically be excluded from all query results.
To determine if a given model instance has been soft deleted, you may use the trashed method:
if ($flight->trashed()) {
//
}
Restoring Soft Deleted Models
Sometimes you may wish to "un-delete" a soft deleted model. To restore a soft deleted model, you may call the restore method on a model instance. The restore method will set the model's deleted_at column to null:
$flight->restore();
You may also use the restore method in a query to restore multiple models. Again, like other "mass" operations, this will not dispatch any model events for the models that are restored:
Flight::withTrashed()
->where('airline_id', 1)
->restore();
The restore method may also be used when building relationship queries:
$flight->history()->restore();
Permanently Deleting Models
Sometimes you may need to truly remove a model from your database. You may use the forceDelete method to permanently remove a soft deleted model from the database table:
$flight->forceDelete();
You may also use the forceDelete method when building Eloquent relationship queries:
$flight->history()->forceDelete();
Querying Soft Deleted Models
As noted above, soft deleted models will automatically be excluded from query results. However, you may force soft deleted models to be included in a query's results by calling the withTrashed method on the query:
use App\Models\Flight;
$flights = Flight::withTrashed()
->where('account_id', 1)
->get();
The withTrashed method may also be called when building a relationship query:
$flight->history()->withTrashed()->get();
Retrieving Only Soft Deleted Models
The onlyTrashed method will retrieve only soft deleted models:
$flights = Flight::onlyTrashed()
->where('airline_id', 1)
->get();this means the object being clicked<a class="view_all" onclick="consoleLogMe(this);" href="javascript:">object being clicked</a>
this means the global object window in this example:<a class="view_all" href="javascript:alertMe(this)">window object</a> --patch or -p is usedgit add --patchSimilar to the above commandgit add -p
Possible answers for the command:
y stage this hunk for the next commit
n do not stage this hunk for the next commit
q quit; do not stage this hunk or any of the remaining hunks
a stage this hunk and all later hunks in the file
d do not stage this hunk or any of the later hunks in the file
...
The complete list of the possible answers is on the link of the notelaravel 8
You can define a route to this controller method like so:
use App\Http\Controllers\UserController;
Route::get('/users', [UserController::class, 'index']);
Route::get('/user/{id}', [UserController::class, 'show']);
Resource Controllers
resourceful route to the controller:
use App\Http\Controllers\PhotoController;
Route::resource('photos', PhotoController::class);
------------------------------------------------------------------------------------
laravel 7, 6, 5
You can define a route to this controller method like so:
Route::get('users', 'UserController@index');
Route::get('user/{id}', 'UserController@show');
Resource Controllers
resourceful route to the controller:
Route::resource('photos', 'PhotoController');
=========================================
This single route declaration creates multiple routes to handle a variety of actions on the resource. The generated controller will already have methods stubbed for each of these actions. Remember, you can always get a quick overview of your application's by running the route:list Artisan command.
Actions Handled By Resource Controller
Verb URI Action Route Name
GET /photos index photos.index
GET /photos/create create photos.create
POST /photos store photos.store
GET /photos/{photo} show photos.show
GET /photos/{photo}/edit edit photos.edit
PUT/PATCH /photos/{photo} update photos.update
DELETE /photos/{photo} destroy photos.destroymysql -u root -p
create a database by typing the following command:
CREATE DATABASE new_database;
To view a list of the current databases that you have created, use the following command:
SHOW DATABASES;