bonjour,

je travaille avec laravel 4
qui peut me corrigé sa
je veut faire un clé etrangere id_show dans les deux table episode et slider
-un show has many episode
-un show has many sliderimage

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
class Admin extends Migration {
 
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('admin',function($table){
			$table->increments('id');
			$table->string('name', 50);
			$table->string('password', 50);
			$table->string('role', 10); //super ou simple
			$table->string('email', 50);
			$table->string('telNumber', 12);
		});
	}
 
	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('admin');
	}
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
class Shows extends Migration {
 
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('Shows',function($table){
			$table->increments('id');
			$table->string('name', 100);
			$table->string('state');
			$table->text('description');
			$table->timestamps();
		});
	}
 
	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('Show');
	}
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
class SliderImages extends Migration {
 
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('sliderImages',function($table){
			$table->increments('id');
			$table->text('imageLink');
			$table->string('state');
			$table->unsignedInteger('show_id');
			$table->foreign('show_id')->references('id')->on('Shows');
		});
	}
 
	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('sliderImage');
	}
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
class Episodes extends Migration {
 
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('Episodes',function($table){
			$table->increments('id');
			$table->string('name', 100);
			$table->text('description');
			$table->timestamps();
			$table->string('animator');
			$table->text('videoLink');
			$table->text('miniatureImageLink');
			$table->unsignedInteger('show_id');
			$table->foreign('show_id')->references('id')->on('Shows');
		});	}
 
	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('Episode');
	}
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
class Shows extends Eloquent{
 
	 protected $table = 'Shows';
	 protected $fillable = array('name', 'state', 'description');
	 protected $guarded = array('id', 'created_at','updated_at');
 
	 public static $rules = array(
	 		'description'=>'required',
	 		'name'=>'required'
	 		);
 
	 public static function validate($data){
 
	 	return Validator::make($data, static::$rules);
	 }
 
	 public function Episodes()
    {
        return $this->hasMany('Episodes');
    }
 
     public function SliderImages()
    {
        return $this->hasMany('SliderImages');
    }
 
	}