من دو تا جدول Users و booksو جدول واسط book_user رو ایجاد کردم و کارهای مربوط به مدل ها و کلید های خارجی رو هم انجام دادم ، ولی نمی دونم چطوری باید متد درج رو پیاده سازی کنم.
bookcontroller:
public function Register_new_book(){ $input_title= Request::get('title'); $input_subject= Request::get('subject'); if($input_subject ==='1'){ $input_subject='مذهبی'; }elseif($input_subject === '2'){ $input_subject='تاریخی'; }elseif($input_subject === '3'){ $input_subject='جغرافیا'; }elseif($input_subject === '4'){ $input_subject= 'علوم پایه'; }elseif($input_subject === '5'){ $input_subject ='علوم مهندسی'; }elseif($input_subject === '6'){ $input_subject ='علوم پزشکی'; }elseif($input_subject === '7'){ $input_subject = 'رمان و داستان'; }else{ $input_subject =''; } $input_writer=Request::get('writer'); $input_summary=Request::get('summary'); $input_translator=Request::get('translator'); $input_b_file= Request::file('b_file'); $book_fileName = time() . '_' . $input_b_file->getClientOriginalName(); $destinationPath = public_path() . '/uploads'; $input_b_file->move($destinationPath, $book_fileName); $book = Book::create([ 'title'=>$input_title, 'subject'=>$input_subject, 'writer'=>$input_writer, 'summary'=>$input_summary, 'b_file'=>$book_fileName, 'translator'=>$input_translator, 'confirmed' => '0', ]);
usermodel:
class User extends Authenticatable { protected $fillable = [ 'username', 'email','password' ]; protected $hidden = [ 'password','remember_token', ]; public function books(){ return $this->belongsToMany('App\Book'); } }
bookmodel:
class Book extends Model { protected $fillable = [ 'title','subject','translator','writer','b_file','summary','confirmed', ]; public function users(){ return $this->belongsToMany('App\User'); } }
ممنون ار راهنماییتون
منظور تون اینه که حالا میخواید تو دیتابیس ثبت کنید ؟؟
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)