Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel model update

Model::where('id',1)->update(['name'=>'updated name']);
//or
$data         = Model::findOrFail($id); //primary id
$data->name   = $request->input('updated name');
$data->save();
Comment

laravel update model from request

public function update(Request $request, Teacher $teacher)
{
    $teachers = $request->all();
    $teacher->save();
    return back()->with('message', 'Record Successfully Updated!');
}
Comment

laravel update model from request

public function update(Request $request, Teacher $teacher)
{
    $input = $request->all();
    $teacher->fill($input)->save();
    return back()->with('message', 'Record Successfully Updated!');
}
Comment

laravel update model from request

public function update(Request $request, $id)
    {
        $supplier = SupplierModel::findOrFail($id);
        $supplier->update($request->all());
        return redirect(route('admin.suppliers.index'))->with('message', 'Поставщик успешно обновлен');
    }
Comment

laravel update method

 public function update(UpdatePostRequest $request, Post $post)
    {
        $request->validate([
        //unique:table,column,id
        "title" => "required|unique:posts,title,".$this->route('post')->id."|min:5",
        "description" => "required|min:15",
        "cover" => "nullable|file|mimes:jpeg,png|max:5000"
        ]);

        $post->title = $request->title;
        $post->slug = Str::slug($request->title);
        $post->description = $request->description;
        $post->excerpt = Str::words($request->description,50);

        if($request->hasFile('cover')){

//            delete old cover
            Storage::delete("public/cover/".$post->cover);

//            upload new cover
            $newName = "cover_".uniqid()."_".$request->file('cover')->extension();
            $request->file('cover')->storeAs("public/cover",$newName);

//            save to table
                $post->cover = $newName;
        }

            $post->update();

        return redirect()->route('post.detail',$post->slug)->with('status','Post Updated');
    }
Comment

PREVIOUS NEXT
Code Example
Php :: laravel 8 routes namespace 
Php :: remove seconds from time php 
Php :: how to install php dependencies 
Php :: number_format reverse php 
Php :: session laravel 
Php :: laravel 6 get user id 
Php :: laravel socialite 
Php :: how to execute cmd command in php 
Php :: Clear from faild_jobs laravel 
Php :: laravel get single column value 
Php :: string convert snake case to title case in laravel 
Php :: rule In in laravel 
Php :: the_post_thumbnail 
Php :: php timezone 
Php :: password encryption php 
Php :: symfony see all make commands 
Php :: php array extract value 
Php :: laravel chunk select 
Php :: how to use stored procedure in laravel 
Php :: php get date between two dates 
Php :: php createFromFormat day of week 
Php :: php calculate hours and minutes between two times 
Php :: foreach skip current iteration 
Php :: php artisan orderByDesc 
Php :: php group multidimensional array by value 
Php :: php Convert String containing commas to array 
Php :: php endwhile 
Php :: encrypt/decrypt data php 
Php :: php echo new line terminal 
Php :: php post request 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =