'roleIds:' . Role::ID__ADMIN . ',' . Role::ID__MODERATOR
'roleIds:' . implode(',', [Role::ID__ADMIN, Role::ID__MODERATOR])
Rule::exists('orders', 'id')->where(function ($query) {
$query->where('user_id', auth()->id());
}),
Хочется, чтобы правила были написаны для каждой модели только один разВ общем случае это некорректное желание - правила валидации могут кардинально различаться для формы редактирования элемента в кабинете пользователя и в админке. Там могут быть разные наборы полей, разные требования для каждого поля, своя обязательность.
public function testCreateImgTest()
{
$this->actingAs($someExistingUser);
$this->get('/create')->assertOk();
}
//Обновление статуса
public function statusUpdate($status)
{
$this->update(['status_id'=>$this->{$status}()]);
}
$product->statusUpdate('active');
class Foo
{
public const ACTIVE = 1;
public const INACTIVE = 2;
public function isActive()
{
return $this->status_id === static::ACTIVE;
}
public function statusUpdate($status)
{
$this->update(['status_id' => $status]);
}
}
(new Foo)->statusUpdate(Foo::ACTIVE);
$objCity->country_id = 1;
$objCity->name = $city;
при переходе через активизирующий метод роутhttps://laravel.com/docs/5.7/seeding
Stacks
Blade allows you to push to named stacks which can be rendered somewhere else in another view or layout. This can be particularly useful for specifying any JavaScript libraries required by your child views:@push('scripts') <script src="/example.js"></script> @endpush
You may push to a stack as many times as needed. To render the complete stack contents, pass the name of the stack to the@stack
directive:<head> <!-- Head Contents --> @stack('scripts') </head>
Customizing The Key Name
If you would like model binding to use a database column other thanid
when retrieving a given model class, you may override thegetRouteKeyName
method on the Eloquent model:/** * Get the route key for the model. * * @return string */ public function getRouteKeyName() { return 'slug'; }
Database Connectionhttps://laravel.com/docs/5.7/eloquent
By default, all Eloquent models will use the default database connection configured for your application. If you would like to specify a different connection for the model, use the $connection property
Using Multiple Database Connectionshttps://laravel.com/docs/5.7/database#using-multip...
When using multiple connections, you may access each connection via the connection method on the DB facade. The name passed to the connection method should correspond to one of the connections listed in your config/database.php configuration file
If you only need the functionality of a custom rule once throughout your application, you may use a Closure instead of a rule object.
Starting The Scheduler
When using the scheduler, you only need to add the following Cron entry to your server:* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
This Cron will call the Laravel command scheduler every minute. When the schedule:run command is executed, Laravel will evaluate your scheduled tasks and runs the tasks that are due.
Sometimes you may wish to eager load a relationship, but also specify additional query constraints for the eager loading query. Here's an example:$users = App\User::with(['posts' => function ($query) { $query->where('title', 'like', '%first%'); }])->get();