Ben bir laravel todo uygulaması oluşturuyorum. Kontrol cihazımda farklı yöntemler var ama içindeki tüm kodlar hemen hemen aynı. Tamamlanmamış yöntem ve tamamlanmış yöntemde, burada madde 1 farklıdır. Bunun dışında tüm kodlar aynıdır. Kod çoğaltmasını nasıl önleyebilirim?php kodu çoğaltması nasıl engellenir burada
public function all()
{
$user_id = $this->user_id;
$todos = $this->todos
->where('user_id', $user_id)
->orderBy('id', 'DESC')->paginate(15);
return view('todos.index', compact('todos'));
}
public function notCompleted()
{
$user_id = $this->user_id;
$todos = $this->todos
->where('user_id', $user_id)
->where('completed', false)
->orderBy('id', 'DESC')->paginate(15);
return view('todos.index', compact('todos'));
}
public function completed()
{
$user_id = $this->user_id;
$todos = $this->todos
->where('user_id', $user_id)
->where('completed', true)
->orderBy('id', 'DESC')->paginate(15);
return view('todos.index', compact('todos'));
}
Bunu yapmış olabilir ama üç rotalar için üç ayrı yöntem gerek bana :) cevap herkese
ve teşekkürler. –