Laravel check if id exists?
Posted
by
devt204
on Stack Overflow
See other posts from Stack Overflow
or by devt204
Published on 2014-06-06T08:51:38Z
Indexed on
2014/06/06
9:25 UTC
Read the original article
Hit count: 148
I've two columns in contents tables 1. id 2. content
now this is what i'm trying to do
Route::post('save', function()
{
$editor_content=Input::get('editor_content');
$rules = array('editor_content' => 'required');
$validator= Validator::make(Input::all(), $rules);
if($validator->passes())
{
//1. check if id is submitted?
//2. if id exists update content table
//3. else insert new content
//create new instance
$content= new Content;
// insert the content to content column
$content->content = $editor_content;
//save the content
$content->save();
// check if content has id
$id=$content->id;
return Response::json(array('success' => 'sucessfully saved', 'id' => $id));
}
if($validator->fails())
{
return $validator->messages() ;
}
});
i wanted to check if id has been already submit or checked i'm processing the request via ajax, and if id exists i wanted update the content column and if it doesn't i wanted to create new instance how do i do it ?
© Stack Overflow or respective owner