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)
{
It works:
$this->id_vendor = $request['id_vendor'];
$this->price = $request['price'];
$this->comission = $request['price'] * 0.085;
$this->save();
Does not 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);
}
}