Reputation: 83
I'm confronted to a little problem, i try to add a method to show only online article, but i want to know how do implement this method. In my DB i have a row is_online (Int) for 0=> offline, 1=>online, how do implement that for my view.
in my models with
public function isonline(){}
or in my PostController in my request of post find.
And after need to add in my admin panel a check box in Post create to change the status off article (online or offline-draft).
Upvotes: 0
Views: 62
Reputation: 6539
You just need to find all records who have flag is_online = 1
.
You can write one method in your PostController
like
Public function getOnlineRecords{
$records = YourModel::where('is_online','=',1)->get();
return View::make('your_view_path',['records'=>$records]);
}
In your View file, you need to write:-
{{ Form::checkbox('your_field_name', 'value', true) }}
If you want to default the value as checked, pass true
as the third argument
.
Upvotes: 0
Reputation: 802
You should use Eloquent
scope in your code by creating online
scope in your model.
public function scopeOnline($query)
{
return $query->where('is_online', 1);
}
Draft posts
public function scopeDrafts($query)
{
return $query->where('is_online', 0);
}
Then in your code you can simply use it like this.
$onlinePosts = Post::online()->get();
$draftPosts = Post::drafts()->get();
Upvotes: 3