1
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Sale extends Model
{
protected $guarded = ['id'];
public function vendor()
{
return $this->hasMany('App\Vendor');
}
public function listSales()
{
return $this->all();
}
public function create($request)
{
Works :
$this->id_vendor = $request['id_vendor'];
$this->price = $request['price'];
$this->comission = $request['price'] * 0.085;
$this->save();
Doesn’t work:
// $teste = $this::create([
// 'id_vendor' => $request['id_vendor'],
// 'price' => $request['price'],
// 'comission' => '$request[\'price\']' * 0.085,
// ]);
return $this->informationVendor($request['id_vendor']);
}
public function informationVendor($id)
{
return DB::table('sales')
->join('vendors', 'vendors.id', '=', 'sales.id_vendor')
->where('sales.id_vendor', $id)
->select('vendors.name', 'vendors.email', 'sales.price', 'sales.comission')
->get()
->take(1);
}
}
Place your class
– novic
Funny because you have created a method that already exists? You are rewriting it including! Your missing class set up fillable ...
– novic