//just run this command in your project directory
composer update
User::where('id', $user_id)
->update([
'name' => $name
]);
$user = User::updateOrCreate(['name' => request()->name], [
'foo' => request()->foo
]);
php composer.phar update
Model::where('id',1)->update(['name'=>'updated name']);
//or
$data = Model::findOrFail($id); //primary id
$data->name = $request->input('updated name');
$data->save();
$user = User::updateOrCreate(
['email' => request('email')],
['name' => request('name')]
);
// Do other things with the User
// If there's a flight from Oakland to San Diego, set the price to $99.
// If no matching model exists, create one.
$flight = AppModelsFlight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
use AppModelsFlight;
$flight = Flight::find(1);
$flight->name = 'Paris to London';
$flight->save();
DB::table('vendor_managements')->where('vendor_code', $vendor_code)->update(array('state'=> $state_namne));
User::query()->whereId($user->id)
->update([
'column' => 'value',
'n' => 'n',
]);
$flight = AppModelsFlight::find(1);
$flight->name = 'New Flight Name';
$flight->save();
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');
}
const CREATED_AT = 'creation_date';
const UPDATED_AT = 'last_update';
<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>