D
D
Dima2015-03-25 02:58:04
Laravel
Dima, 2015-03-25 02:58:04

How to get the status of a database entry in Laravel 5?

A couple of days ago I started learning Laravel 5 and ran into such a nuisance. For example, I create a database entry like this:

$post = new Post;
$post->title = $title;
$post->teaser = $teaser;
$post->body = $body;
$post->slug = $slug;
$post->image270 = $image270;
$post->enabled = 1;
$post->save();

But if the update ( Post::where('id', '=', $id)->update(...); ) returns a boolean value, which allows comparison operators to be used, this doesn't work in this example. How can I follow the next steps depending on whether the record was successfully created or not?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
enixpp, 2015-03-25
@avbrugen

if ($post->save()){
    ...
}

F
FanatPHP, 2015-03-25
@FanatPHP

And why check and what actions are you going to perform if it was not possible to create?
And have you tried to perform such actions when updating?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question