samedi 27 juillet 2019

Trying to get property of non-object in laravel 5.8

i want to show the name of the category in post table but this give me error here my code check this

this is the modal

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Post extends Model
{

    protected $fillable=['seotitle', 'h1title', 'image' , 'alt', 'url' , 'meta','author','status','keywords', 'tags', 'category_id', 'text','read', 'view'];


    public function Category(){

        return $this->belongsTo(Category::class);
    }
}

i also use the fillable for 'name' in category modal

post controller

namespace App\Http\Controllers;
use DB;
use App\Post;
use App\categoriesegory;
use Illuminate\Http\Request;
use App\Http\Requests\Posts\CreatePostsRequest;
use App\Http\Requests\Posts\UpdatePostRequest;
use Illuminate\Support\Facades\Storage;
public function index()
    {
        // $select=DB::select("SELECT * From posts where status='publish'");    
        return view('/admin/posts/index')->with('posts' , Post::all());
    }

blade file

<td>{‌{$post->Category->name}}</td>

Category= this is modal function name in relationship

how can i solve this issue ?

i want to show the name of category in the post table but getting error can you show me what the issue laravel 5.8



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2LGU7bj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire