Conversation
|
@minhquang97 : ở model nào e viết eloquent relation thì có thể sử dụng orm để query relation phía bên model đó, ko viết 1 bên dùng đc cả 2 bên đc. ví dụ e có 2 model là User + Post có quan hệ 1-n, nếu ở model User có :
|
|
@thanhnt-hapo em đã hiểu rồi ạ. |
| @@ -0,0 +1,25 @@ | |||
| <?php | |||
There was a problem hiding this comment.
@@ em quên không xóa
| @@ -23,8 +23,9 @@ public function authorize() | |||
| public function rules() | |||
There was a problem hiding this comment.
@minhquang97 cái này là dùng cho cả create và update à e ?
There was a problem hiding this comment.
đúng rồi a. Em dùng cái này cho cả 2 luôn.
app/Model/Classes.php
Outdated
|
|
||
| class Classes extends Model | ||
| { | ||
| protected $table = "classes"; |
There was a problem hiding this comment.
@minhquang97 tên Class để ở dạng số ít thôi e, k cần khai báo $table khi e để tên class ở dạng số ít, tên bảng ở dạng số nhiều
There was a problem hiding this comment.
cái này em lỡ tay đặt tên classes rồi nên em phải định nghĩa table. em sẽ sửa lại.
app/Model/Classes.php
Outdated
| { | ||
| protected $table = "classes"; | ||
| protected $fillable = [ | ||
| 'id','teacher_id','subject_id','semester' |
app/Model/Classes.php
Outdated
|
|
||
| public function teacher() | ||
| { | ||
| return $this->belongsto('App\Model\Teacher'); |
There was a problem hiding this comment.
@minhquang97 khi viết relation các class viết theo form Teacher::class
There was a problem hiding this comment.
nghĩa là App\Model\Teacher::class
| @@ -4,11 +4,10 @@ | |||
|
|
|||
There was a problem hiding this comment.
@minhquang97 model này đang dùng cho student à e ?
There was a problem hiding this comment.
không ạ. cái này là tài khoản để user để học sinh login vào xem thông tin, điểm cá nhân, với em dự định sẽ tạo thêm một admin để quản lý học sinh nữa.
composer.json
Outdated
| "optimize-autoloader": true | ||
| } | ||
| , | ||
| "repositories": [ |
|
|
||
| <div class="form-group"> | ||
| <div class="col-md-8 col-md-offset-4"> | ||
| <a href="{{url('/redirect')}}" class="btn btn-primary">Login with Facebook</a> |
There was a problem hiding this comment.
@minhquang97 Login sao dùng url này nhỉ ?
There was a problem hiding this comment.
em sử dụng trong route Route::get('/redirect', 'SocialAuthFacebookController@redirect');
Problem về phần Eloquent là nếu xét một quan hệ thì có cần phải viết eloquent cho cả 2 đối tượng trong quan hệ đó ko. Ví dụ A và B là quan hệ one many. Thì bên A viết là hasMany()... bên B cũng viết là belongstoMany() ????