【发布时间】:2017-04-18 08:59:36
【问题描述】:
我正在尝试为 iOS 应用设置我的 API。这是我第一次使用 Laravel 作为 API,所以这是我的表格中的内容:
汽车
Schema::create('cars', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('age')->nullable();
$table->string('model')->nullable();
$table->string('color')->nullable();
用户
$table->increments('id');
$table->string('name')->nullable();
$table->string('street')->nullable();
$table->string('niehgborhood')->nullable();
$table->string('city')->nullable();
合同
$table->increments('id');
$table->integer('user_id')->unsigned;
$table->foreign('user_id')->references('id')->on('users');
$table->integer('car_id')->unsigned;
$table->foreign('car_id')->references('id')->on('cars');
模型
protected $table = 'users';
protected $guarded = ['id'];
protected $fillable = ['phone', 'email',
'street','city','niehgborhood'
,'national_id'];
public function cars()
{
return $this->hasMany('App\User');
}
用户
protected $guarded = ['id'];
protected $fillable = ['name', 'age',
'color, model'
];
public function users()
{
return $this->belongsToMany('App\Cars');
}
在我的控制器中,我熟悉保存请求的数据
$user = JWTAuth::parseToken()->authenticate();
$user->phone = $request->phone;
$user->city = $request->city;
$user->save();
我对这个项目的目标是在我的仪表板中显示 iOS 应用程序用户保存的数据(合同)。例如,用户信息和他们对我的表感兴趣的汽车。有人可以帮我在控制器中查询什么(不是视图)。或者为此类项目提供有用的链接。
【问题讨论】:
标签: ios mysql laravel orm eloquent