0% found this document useful (0 votes)
25 views10 pages

(FA21-BCS-097) Assignment#4

fewfwefwegweg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views10 pages

(FA21-BCS-097) Assignment#4

fewfwefwegweg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

COMSATS UNIVERSITY ISLAMABAD

Assignment # 04

 NAME Muneeb Ahmad Bhatti


 CLASS CS 5B
 REGISTRATON NUMBER FA21-BCS-097
 DEPARTMENT COMPUTER SCIENCE
 COURSE Web Tech

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.

Displaying list of all the movies currently in database:


Create new movie page that opens from button “Add new movie”:

Movie stored in database:


Single Movie displayed after clicking on the movie:

Edit Movie screen opens when clicked on “Edit” button:

Movie Updated Successfully:


Code
web.php:

<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('welcome');
});

use App\Http\Controllers\MovieController;

Route::get('/movies', [MovieController::class, 'index'])->name('index');


Route::get('/movies/create', [MovieController::class, 'create'])->name('create');
Route::post('/movies', [MovieController::class, 'store'])->name('store');
Route::get('/movies/{movie}', [MovieController::class, 'show'])->name('show');
Route::get('/movies/{movie}/edit', [MovieController::class, 'edit'])->name('edit');
Route::put('/movies/{movie}', [MovieController::class, 'update'])->name('update');

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;

class MovieController extends Controller


{
public function index()
{
$movies = Movie::all();
return view('index', compact('movies'));
}

public function create()


{
return view('create');
}

public function store(Request $request)


{
$request->validate([
'title' => 'required|max:100',
'duration' => 'required|max:20',
'year' => 'required|integer',
]);

Movie::create($request->all());

return redirect()->route('index');
}

public function show(Movie $movie)


{
return view('show', compact('movie'));
}

public function edit(Movie $movie)


{
return view('edit', compact('movie'));
}

public function update(Request $request, Movie $movie)


{
$request->validate([
'title' => 'required|max:100',
'duration' => 'required|max:20',
'year' => 'required|integer',
]);

$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.

You might also like