xxxxxxxxxx
$flight = App\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
// updates price and discounted or creates a new record
xxxxxxxxxx
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
xxxxxxxxxx
$user = User::updateOrCreate(
['name' => request()->name], //Try to match this
['foo' => request()->foo] //Data to be created/updated including the first parameter
);
xxxxxxxxxx
$user = User::updateOrCreate(
['email' => request('email')],
['name' => request('name')]
);
// Do other things with the User
xxxxxxxxxx
// If there's a flight from Oakland to San Diego, set the price to $99.
// If no matching model exists, create one.
$flight = App\Models\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
xxxxxxxxxx
$newUser = \App\UserInfo::updateOrCreate([
//Add unique field combo to match here
//For example, perhaps you only want one entry per user:
'user_id' => Auth::user()->id,
],[
'about' => $request->get('about'),
'sec_email' => $request->get('sec_email'),
'gender' => $request->get("gender"),
'country' => $request->get('country'),
'dob' => $request->get('dob'),
'address' => $request->get('address'),
'mobile' => $request->get('cell_no')
]);
xxxxxxxxxx
DB::table('vendor_managements')->where('vendor_code', $vendor_code)->update(array('state'=> $state_namne));
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');
}