xxxxxxxxxx
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');
}
xxxxxxxxxx
$flight = App\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
// updates price and discounted or creates a new record
xxxxxxxxxx
public function update(Request $request, Teacher $teacher)
{
$teachers = $request->all();
$teacher->save();
return back()->with('message', 'Record Successfully Updated!');
}
xxxxxxxxxx
public function update(Request $request, $id)
{
$supplier = SupplierModel::findOrFail($id);
$supplier->update($request->all());
return redirect(route('admin.suppliers.index'))->with('message', 'Поставщик успешно обновлен');
}
xxxxxxxxxx
public function update(Request $request, Teacher $teacher)
{
$input = $request->all();
$teacher->fill($input)->save();
return back()->with('message', 'Record Successfully Updated!');
}
xxxxxxxxxx
use App\Models\Flight;
$flight = Flight::find(1);
$flight->name = 'Paris to London';
$flight->save();
xxxxxxxxxx
$flight = App\Models\Flight::find(1);
$flight->name = 'New Flight Name';
$flight->save();
xxxxxxxxxx
User::query()->whereId($user->id)
->update([
'column' => 'value',
'n' => 'n',
]);
xxxxxxxxxx
<form action="{{route('blog.update',$blog[0]->id)}}" method="post">
@csrf
@method('PUT')
<textarea name="txtTitle" >
{{$blog[0]->title}}
</textarea>
<input type="submit" value="Update" />
</form>