Reputation: 997
I would like to limit only one entry in the table and I am not sure how to do it.
I've read about firstOrCreate but in my model I have:
use Illuminate\Database\Eloquent\Model;
class Ad extends Model
{
protected $fillable = [
'title',
'description',
'image'
];
}
Basically I want to use it for some advertising box on website but only one will be visible. So I don't want to loop over and show for example last one.
How can I achieve this?
Thank you.
Upvotes: 0
Views: 336
Reputation: 163848
Since you want to have only one ad in a table the first()
method to get it:
$ad = Ad::first();
Upvotes: 1