Skip to content
This repository was archived by the owner on Oct 28, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
617 changes: 363 additions & 254 deletions .idea/workspace.xml

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions app/Actor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

class Actor extends Model
{
protected $fillable = [
'name', 'bio', 'movies'
];

/** belongsToMany movies */
public function movies() {
public function movies()
{
return $this->belongsToMany(Movie::class);
}

/** hasMany quote */
public function quotes() {
public function quotes()
{
return $this->hasMany(Quote::class);
}
}
16 changes: 4 additions & 12 deletions app/ActorMovie.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Pivot;

class ActorMovie extends Model
class ActorMovie extends Pivot
{
/** hasMany movies */
public function movie() {
return $this->hasMany(Movie::class, 'movie_id');
}

/** hasMany actors */
public function actor() {
return $this->hasMany(Actor::class, 'actor_id');
}
}
//
}
6 changes: 3 additions & 3 deletions app/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class Director extends Model
{
/** belongsTo movie */
public function movie() {
return $this->belongsTo(Movie::class);
/** hasMany movie */
public function movies() {
return $this->hasMany(Movie::class);
}
}
50 changes: 46 additions & 4 deletions app/Http/Controllers/MovieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace App\Http\Controllers;

use App\Actor;
use App\Movie;
use Illuminate\Http\Request;
use App\Director;

class MovieController extends Controller
{
Expand All @@ -21,11 +22,52 @@ public function index()
/**
* Display the specified resource.
*
* @param Movie $movie
* @param Movie $movie
* @param Actor $actor
* @return \Illuminate\Http\Response
*/
public function show(Movie $movie)
public function show(Movie $movie, Actor $actor)
{
return view('movies.show')->with('movie', $movie);
$movie->load('actors');
$movie->load('quotes');

$director = $movie->director;
$language = $movie->language;
$actors = $movie->actors;
$quotes = $movie->quotes;


return view('movies.show')->with(compact('movie', 'director', 'language', 'actors', 'quotes'));
}

/**
* Display the specified resource.
*
* @param Actor $actor
* @return \Illuminate\Http\Response
*/
public function actor(Actor $actor)
{
$actor->load('movies');

$movies = $actor->movies;


return view('actor.actorPage')->with(compact('actor', 'movies'));
}

/**
* Display the specified resource.
*
* @param Director $director
* @return \Illuminate\Http\Response
*/
public function director(Director $director)
{
$director->load('movies');

$movies = $director->movies;

return view('director.director')->with(compact('director', 'movies'));
}
}
6 changes: 3 additions & 3 deletions app/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class Language extends Model
{
/** belongsTo movie */
public function movie() {
return $this->belongsTo(Movie::class);
/** hasMany movie */
public function movies() {
return $this->hasMany(Movie::class);
}
}
10 changes: 5 additions & 5 deletions app/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ public function quotes()
/** has many actors */
public function actors()
{
return $this->hasMany(Actor::class);
return $this->belongsToMany(Actor::class);
}

/** has one director */
public function director()
{
return $this->hasOne(Director::class, 'director_id');
return $this->belongsTo(Director::class);
}

/** has many actors */
public function Language()
/** has many language */
public function language()
{
return $this->hasOne(Language::class, 'language_id');
return $this->belongsTo(Language::class);
}
}
2 changes: 1 addition & 1 deletion config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'bootcamp-1'),
'database' => env('DB_DATABASE', 'movieDB'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
Expand Down
5 changes: 4 additions & 1 deletion database/factories/ActorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
return [
'name' => $faker->name,
'bio' => $faker->text(),
'image' => 'images/lupita.jpg',
'fullname' => '',
'born' => '',
'height' => '',
'image' => 'images/lupita.jpg'
];
});
8 changes: 6 additions & 2 deletions database/factories/ActorMovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

$factory->define(ActorMovie::class, function (Faker $faker) {
return [
'actor_id' => 1,
'movie_id' => 1
'actor_id' => function () {
return factory(\App\ActorMovie::class)->create()->id;
},
'movie_id' => function () {
return factory(\App\ActorMovie::class)->create()->id;
}
];
});
5 changes: 5 additions & 0 deletions database/factories/DirectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
$factory->define(Director::class, function (Faker $faker) {
return [
'name' => $faker->name,
'fullname' => '',
'born' => '',
'height' => '',
'image' => 'images/peele.jpg',
'bio' => $faker->text(),
];
});
2 changes: 1 addition & 1 deletion database/factories/LanguageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

$factory->define(Language::class, function (Faker $faker) {
return [

'language' => 'English'
];
});
6 changes: 6 additions & 0 deletions database/factories/MovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
'title' => $faker->title,
'description' => $faker->text(),
'image' => 'images/search.png',
'director_id' => function () {
return factory(\App\Director::class)->create()->id;
},
'language_id' => function () {
return factory(\App\Language::class)->create()->id;
}
];
});
8 changes: 6 additions & 2 deletions database/factories/QuoteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

$factory->define(Quote::class, function (Faker $faker) {
return [
'actor_id' => 1,
'movie_id' => 1,
'actor_id' => function () {
return factory(\App\Quote::class)->create()->id;
},
'movie_id' => function () {
return factory(\App\Quote::class)->create()->id;
},
'quote' => $faker->text(),
];
});
3 changes: 3 additions & 0 deletions database/migrations/2019_07_01_021319_create_actors_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public function up()
Schema::create('actors', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('fullname');
$table->string('born');
$table->string('height');
$table->text('bio');
$table->string('image');
$table->timestamps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateActorMovieTable extends Migration
*/
public function up()
{
Schema::create('actor_movies', function (Blueprint $table) {
Schema::create('actor_movie', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('actor_id')->unsigned();
$table->integer('movie_id')->unsigned();
Expand All @@ -28,6 +28,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('actor_movies');
Schema::dropIfExists('actor_movie');
}
}
2 changes: 2 additions & 0 deletions database/migrations/2019_07_01_054138_create_movies_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function up()
$table->text('title');
$table->string('description');
$table->string('image');
$table->integer('director_id');
$table->integer('language_id');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public function up()
Schema::create('directors', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->integer('movie_id')->unsigned();
$table->string('fullname');
$table->string('born');
$table->string('height');
$table->string('image');
$table->string('bio');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public function up()
Schema::create('languages', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('language');
$table->integer('movie_id')->unsigned();
$table->timestamps();
});
}
Expand Down
50 changes: 49 additions & 1 deletion database/seeds/ActorMoviesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,54 @@ class ActorMoviesTableSeeder extends Seeder
*/
public function run()
{
factory(App\ActorMovie::class)->create();
factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'Lupita Nyongo')->first()->id,
'movie_id' => \App\Movie::where('title', 'US')->first()->id
]);

factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'Wiston Duke')->first()->id,
'movie_id' => \App\Movie::where('title', 'US')->first()->id
]);

factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'Elizabeth Moss')->first()->id,
'movie_id' => \App\Movie::where('title', 'US')->first()->id
]);

factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'Tim Hiedecker')->first()->id,
'movie_id' => \App\Movie::where('title', 'US')->first()->id
]);

factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'Will Smith')->first()->id,
'movie_id' => \App\Movie::where('title', 'Aladdin')->first()->id
]);

factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'Mena Massound')->first()->id,
'movie_id' => \App\Movie::where('title', 'Aladdin')->first()->id
]);

factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'Naomi Scott')->first()->id,
'movie_id' => \App\Movie::where('title', 'Aladdin')->first()->id
]);

factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'Marwan Kenzari')->first()->id,
'movie_id' => \App\Movie::where('title', 'Aladdin')->first()->id
]);

factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'Adam Sandler')->first()->id,
'movie_id' => \App\Movie::where('title', 'Zohan')->first()->id
]);

factory(App\ActorMovie::class)->create([
'actor_id' => \App\Actor::where('name', 'John Turturro')->first()->id,
'movie_id' => \App\Movie::where('title', 'Zohan')->first()->id
]);
}
}
Loading