laravel findorfail
$model = App\Flight::where('name', 'Mike')->firstOrFail();
laravel findorfail
$model = App\Flight::where('name', 'Mike')->firstOrFail();
laravel create model
# The easiest way to create a model instance is using the
# make:model Artisan command:
php artisan make:model Flight
# If you would like to generate a database migration when you
# generate the model, you may use the --migration or -m option:
php artisan make:model Flight --migration
php artisan make:model Flight -m
fresh laravel
$flight = Flight::where('number', 'FR 900')->first();
$flight->number = 'FR 456';
$flight->refresh();
$flight->number; // "FR 900"
laravel firstorcreate
// Retrieve flight by name, or create it if it doesn't exist...
$flight = App\Flight::firstOrCreate(['name' => 'Flight 10']);
// Retrieve flight by name, or create it with the name, delayed, and arrival_time attributes...
$flight = App\Flight::firstOrCreate(
['name' => 'Flight 10'],
['delayed' => 1, 'arrival_time' => '11:30']
);
// Retrieve by name, or instantiate...
$flight = App\Flight::firstOrNew(['name' => 'Flight 10']);
// Retrieve by name, or instantiate with the name, delayed, and arrival_time attributes...
$flight = App\Flight::firstOrNew(
['name' => 'Flight 10'],
['delayed' => 1, 'arrival_time' => '11:30']
);
laravel where has
use Illuminate\Database\Eloquent\Builder;
// Retrieve posts with at least one comment containing words like foo%...
$posts = App\Post::whereHas('comments', function (Builder $query) {
$query->where('content', 'like', 'foo%');
})->get();
// Retrieve posts with at least ten comments containing words like foo%...
$posts = App\Post::whereHas('comments', function (Builder $query) {
$query->where('content', 'like', 'foo%');
}, '>=', 10)->get();
laravel soft delete
/** in migrations this changes need to
add for table we want to add soft delete (LARAVEL)*/
/** The migrations. START */
public function up()
{
Schema::table('users', function(Blueprint $table)
{
$table->softDeletes();
});
}
/** The migrations. END */
/** after adding softdelete you need to
point that column in table related model (LARAVEL)*/
/** The Model. START */
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Model {
use SoftDeletes;
protected $dates = ['deleted_at'];
}
/** The Model. END */
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us