Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

302
Views
what is the update method in laravel 5.4 crud?

i just trying to crud system. for that into controller store function my code is

 public function store(Request $request)
{
    Article::create([
        'user_id' => auth()->id(),
        'content' => $request->content,
        'live' => (boolean)$request->live,
        'post_on' => $request->post_on
        ]);

    return redirect('/articles');
}

it's enough to store data, but when i want to edit article & save again then what will be my edit function code? i have no idea. i trying same code into edit function & it create new article not update. so what will be right code for edit function? thanks

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Resource controller method for update is update(). Eloquent method for update() is update() too, so you can do this:

public function update(Request $request, $id)
{
    Article::where('id', $id)->update($request->all());
    return redirect('/articles');
}

You also can use the same controller and Eloquent method for both crerate and update data updateOrCreate() method.

over 4 years ago · Santiago Trujillo Report

0

You can also update it as object format like this.

public function update(Request $request, $id)
{
   $article = Article::find($id);
   $article->user_id = auth()->id();
   $article->content = $request->content;
   $article->live = (boolean)$request->live;
   $article->post_on = $request->post_on;
   $article->save();
}`
over 4 years ago · Santiago Trujillo Report

0

//route//
Route::any('/update/{id}', 'ProductController@update');

//controller//

 public function update(Request $request, $id) {
 $product = $request - > all();

 Product::find($id) - > update($product);
 return redirect('/product') - > with('message', 'Success', compact('product'));
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!