BadMethodCallException in Builder.php line 2405:
Call to undefined method Illuminate\Database\Query\Builder::customers()
我的服务班级:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Service extends Model
{
protected $fillable = [
'title', 'type','link','description','customer_id','user_id'
];
public $timestamps = false;
public function customers(){
return $this->belongsTo('App\Customer');
}
public function user(){
return $this->belongsTo('App\User');
}
}
我的ServiceController类:
class ServiceController extends Controller
{
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'title' => 'required|unique:customers|max:255',
'type' => 'required',
'link' => 'required',
'description' => 'required',
]);
$services = new Service();
$services->title = $request['title'];
$services->type = $request['type'];
$services->link = $request['link'];
$services->description = $request['description'];
$services->customer_id = Customer::customers()->id;
$services->save();
return redirect('/services');
}