vendredi 4 août 2017

Why eloquent property does not exist on this collection instance?

I have a table with column ID, and three text field and the model name is Post

public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title', 256);
        $table->string('title', 256);
        $table->text('body');
        $table->timestamps();
    });
}

While getting data from this table and return the eloquent object from controller and view as <p></p>, it's fine but while accessing the property title as <p></p> it's puts an error.

class BlogController extends Controller
{
    public function single($slug){
        $post = Post::where('slug', '=', $slug)->get();
        //return $post;
        return view('posts.single')->withPost($post);
    }
}

Error:

Property [title] does not exist on this collection instance



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

Aucun commentaire:

Enregistrer un commentaire