Level 9
Problem solved...
public function show(CMSPost $post)
{
// $articles = CMSPost::findOrFail($id);
//$articles = CMSPost::find($post);
dd($post);
// return view('cms.post.show',compact('post));
}
Output
^ null
Basically I want fetch record using routekeyname in url...In url key name is shown but data is not diplaying... This is my show function
public function show($post)
{
// $articles = CMSPost::findOrFail($id);
$articles = CMSPost::find($post);
dd($articles);
// return view('cms.post.show',array('articles' => $articles));
}
And this is my Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class CMSPost extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $table ='cms_posts';
protected $primaryKey = 'id';
protected $fillable = array('category_id','title','author','show_date','image','description','status','user_id','slug',
'visit_count','aslug','subcategory_id','draft');
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
{
return 'aslug';
}
public function category()
{
return $this->belongsTo('App\CMSCategory','category_id');
}
public function user(){
return $this->belongsTo('App\User','user_id');
}
public function mediaLibrary(){
return $this->belongsTo('App\mediaLibrary','image');
}
// public function tags()
// {
// return $this->belongsToMany(CMSTag::class);
// }
}
And this is my route
Route::group(['prefix' => 'cms', 'middleware' => 'auth'], function()
{
Route::resource('/post','CMSPostController');
}
Problem solved...
public function show(CMSPost $post)
{
// $articles = CMSPost::findOrFail($id);
//$articles = CMSPost::find($post);
dd($post);
// return view('cms.post.show',compact('post));
}
Please or to participate in this conversation.