Article::where('alias',$alias)
->latest()
->take($take)
->paginate($paginate);
Category::with(['articles' => function($query) use ($alias,$take) {
$query->where('alias',$alias)->запрос;
}])->запрос->paginate($paginate);
$product = Product::find($product_id);
// hasMany
$product->category->delete();
// manyToMany
$product->categories()
->find($category_id)
->delete();
// Просто удалить категорию
Category::find($id)->delete();
// Удалить категорию У товара (открепить)
$product->categories()
->detach($category_id);
Product::with(['relatedSpecsGroup' => function($query) {
$query->orderBy('position', 'desc');
}])
->orderBy('relatedValue', 'desc')
->get();
// удаляем поле
Schema::table('auto', function (Blueprint $table) {
$table->dropColumn('remove_field');
});
// добавляем поле
Schema::table('auto', function (Blueprint $table) {
$table->integer('add_field')->nullable();
});
$slug = Str::slug($name);
Route::get('{slug_category}/{slug_post}', 'PostController@show')->name('post.show');
{{route('post.show', [$category->slug,$post->slug])}}
$user = Auth::user();
if ($user->isAdmin) {
// code...
}else{
// code...
}
// не админ
if (!$user->isAdmin) {
// code...
}
'/{user}/orders'
$user=User::find($user_id);
$orders = $user->orders;
public function news()
{
return $this->belongsToMany('App\News', 'news_to_rubric', 'rubric_id', 'news_id');
}
$rubrics = Rubric::with('news')
->get();
@foreach ($rubrics as $rubric)
{{$rubric->name}}
@foreach ($rubric->news as $news)
{{ $news->name }}
@endforeach
@endforeach
$schedule->call(function(){
(new \App\Http\Controllers\ParserController)->parserSite1();
})->everyMinute();
User::find($id);