(FA21-BCS-097) Assignment#4
(FA21-BCS-097) Assignment#4
Assignment # 04
Introduction
In this project, we set out to create a simple yet aesthetically pleasing movie review website using the
Laravel framework. The application is designed to manage movie records with functionality to display a
list of movies, view details of a single movie, add new movies, and edit existing movies. By leveraging
Laravel's routing, controllers, and Blade templating system, we created a structured and maintainable web
application. Additionally, we integrated Bootstrap to enhance the user interface, making it visually
appealing and user-friendly.
Output
Created a movies database with movies table that will store records of all the movies.
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
use App\Http\Controllers\MovieController;
index.blade.php file:
@extends('layouts.app')
@section('content')
<div class="card">
<div class="card-header">
<h1>Movies</h1>
</div>
<div class="card-body">
<a href="{{ route('create') }}" class="btn btn-primary mb-3">Add New Movie</a>
@if($movies->isEmpty())
<p>No movies available.</p>
@else
<ul class="list-group">
@foreach ($movies as $movie)
<li class="list-group-item d-flex justify-content-between align-items-
center">
<a href="{{ route('show', $movie->id) }}">{{ $movie->title }}</a>
<a href="{{ route('edit', $movie->id) }}" class="btn btn-sm btn-
secondary">Edit</a>
</li>
@endforeach
</ul>
@endif
</div>
</div>
@endsection
create.blade.php file:
@extends('layouts.app')
@section('content')
<div class="card">
<div class="card-header">
<h1>Add New Movie</h1>
</div>
<div class="card-body">
<form action="{{ route('store') }}" method="POST">
@csrf
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" name="title"
value="{{ old('title') }}">
</div>
<div class="form-group">
<label for="duration">Duration</label>
<input type="text" class="form-control" id="duration" name="duration"
value="{{ old('duration') }}">
</div>
<div class="form-group">
<label for="year">Year</label>
<input type="text" class="form-control" id="year" name="year"
value="{{ old('year') }}">
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>
</div>
@endsection
edit.blade.php file:
@extends('layouts.app')
@section('content')
<div class="card">
<div class="card-header">
<h1>Edit Movie</h1>
</div>
<div class="card-body">
<form action="{{ route('update', $movie->id) }}" method="POST">
@csrf
@method('PUT')
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" name="title" value="{{ $movie-
>title }}">
</div>
<div class="form-group">
<label for="duration">Duration</label>
<input type="text" class="form-control" id="duration" name="duration"
value="{{ $movie->duration }}">
</div>
<div class="form-group">
<label for="year">Year</label>
<input type="text" class="form-control" id="year" name="year" value="{{ $movie-
>year }}">
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
@endsection
show.blade.php file:
@extends('layouts.app')
@section('content')
<div class="card">
<div class="card-header">
<h1>{{ $movie->title }}</h1>
</div>
<div class="card-body">
<p><strong>Duration:</strong> {{ $movie->duration }}</p>
<p><strong>Year:</strong> {{ $movie->year }}</p>
<a href="{{ route('index') }}" class="btn btn-primary">Back to list</a>
</div>
</div>
@endsection
app.blade.php file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movie Review</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
rel="stylesheet">
<style>
body {
background-color: #f8f9fa;
}
.container {
margin-top: 50px;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
.form-control {
margin-bottom: 10px;
}
.btn-primary {
background-color: #007bff;
border: none;
}
</style>
</head>
<body>
<div class="container">
@yield('content')
</div>
</body>
</html>
MovieController.php file:
<?php
namespace App\Http\Controllers;
use App\Models\Movie;
use Illuminate\Http\Request;
Movie::create($request->all());
return redirect()->route('index');
}
$movie->update($request->all());
return redirect()->route('index');
}
}
Conclusion
Through the development of this movie review website, we gained valuable insights into several core
aspects of Laravel and web development in general. We learned how to define routes and controllers to
handle various action within the application, such as displaying lists, showing individual records, and
managing form submissions for creating and updating movie data. The project also reinforced the
importance of validation and mass assignment in handling user input securely and efficiently. By
incorporating Bootstrap, we enhanced our understanding of how to quickly implement responsive and
modern UI designs, ensuring that our application is not only functional but also attractive. Overall, this
project provided a comprehensive overview of full-stack development using Laravel, from back-end logic
to front-end presentation, equipping us with the skills to build robust and aesthetically pleasing web
applications.