Is it bad practice to use the same method for SAVE and UPDATE?

Nothing wrong, but you code will be harder to understand, IMHO.

e.g.:

  • What does this method do? It's called create, but it also edits?
  • The view is called shop-create but it also edits?
  • Passing a 0 parameter as default for id and trying to find it every time is unnecessary.

public function create($id  = 0)
{
    return view('shop-create' , ['edit'=> Shop::find($id)]);
}

Although you're thinking that you are simplifying your code, you are turning it more complicated since you are breaking the Single Responsibility principle from SOLID.

It's easier to understand if you have something like the Laravel suggestion.

Also you keep a very common pattern that any Laravel developer will understand, so you can hire someone to take care of your code and do not worry if he will understand.


There is nothing wrong with doing it your way. The "laravel" way you mention is when you create a Restful resource controller and is simply one way to tackle it.

I guess those controller methods were picked because they line up nicely to a "restful" type of controller. If you were to be building a true rest api, then how you do it becomes far more strict from a standards point of view (not imposed by laravel, but line up better to the laravel way).

If you aren't creating a public facing api, or something that is going to be consumed by external entities, then I say design your controllers that work best for you and your team


This is how i usually do it, this way you can still have different validation by using the requests and it's still clear (imo) what the functions do.

public function store(AdminPartnerRequest $request)
{
    return $this->handleCreateOrUpdate($request);
}

public function update(AdminPartnerRequest $request, $id)
{
    return $this->handleCreateOrUpdate($request,true, $id);
}


private function handleCreateOrUpdate($request, $edit = false, $id = null)
{
   if ($edit){
       $partner = Partner::find($id);
   } else{
       $partner = new Partner();
   }

        $partner->name = $request->input('name');
        $partner->picture = $request->input('image');         
        $partner->save();

        return \Redirect::route('admin.partners.index');
}