Get attribute from selected model

I am using PHP 7.1.33 and Laravel Framework 5.8.36.

I am getting a model back by name like the following Product::where('name', '=', $name)->get();

My Product model looks like the following:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'product';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'url', 'category'];
}

When trying to get an attribute like the following I get an error:

$product = Product::where('name', '=', $name)->get();
$product->$url; // ERROR
$product->$category; // ERROR

Any suggestions how to access the attributes on my retrieved model?

I appreciate your replies!



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

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time