Trying to get property 'name' of non-object (View: E:\lara-test\resources\views\posts\show.blade.php)

Posted 6 months ago by jet

I am trying to display the name of the category in the form

show form


    <div class="row">
        <div class="col-md-8">
            <h1>{{ $post->title }}</h1>
            <h4>{{ $post->order }}</h4>
            <h4>{{ $post->category_id }}</h4>
            <p class="lead">{{ $post->content }}</p>
            <h4>{{ $post->status }}</h4>

        <div class="col-md-4">
            <div class="well">

                <dl class="dl-horizontal">
                    <p>{{ $post->category->name }}</p>

                <dl class="dl-horizontal">
                    <lable>Create At:</lable>
                    <p>{{ date('M j, Y h:ia', strtotime($post->created_at)) }}</p>

category controller

 public function index()
        $categories = Category::all();
        return view('categories.index')->withCategories($categories);

     * Store a newly created resource in storage.
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
    public function store(Request $request)
        //Save a new category an then redirect back ti index
        $this->validate($request, array(
            'name' => 'required|max:255'
         $category = new Category;

         $category->name = $request->name;

         Session::flash('success', 'New Category has been created');

         return redirect()->route('categories.index');

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.