Laravel at the moment is at version 5.3. In class we have been using Laravel 5.2.
This is a major upgrade:
- Laravel 5.3 has a host of upgrades to its basic services
- Structure of its various constructs has changed
- It uses PHP 5.6 or 7 as opposed to
##Step 1
Go to https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-ubuntu-14-04
Ignore the nginx commands. Run all the others.
##Step 2
We now need to install some php extensions that laravel needs to secure your application.
Run the following commands on your bash terminal.
sudo apt-get install php7.0-mbstring
sudo apt-get install php7.0-xml
sudo apt install php libapache2-mod-php
sudo a2dismod php5
sudo a2enmod php7.0
sudo service apache2 restart
Run server. Confirm is working
##Step 2
We need to install Laravel. Our usual link will do
https://community.c9.io/t/getting-started-with-laravel/1608
##Step 3
Now you should see the new Laravel welcome page.
As usual run the scaffolding for user generation
php artisan make:auth
##Step 4 Migrate the database
We now need to migrate our database. To accomplish this, we first download all our migration files from the old system.
Once this is done. Extract the downloaded files. Move to the new c9 environment, go to the database migrations folder and upload the new file.
Once the files are uploaded. You can now run the migrations.
Run
php artisan migrate
Your database structure now exists in the new db.
##Step 5 Migrate the models
In my old app, I had 3 models
- Course
- Student
- Facility
- User
The User model already exists. So I just need to create the rest by running the following commands.
php artisan make:model Course
php artisan make:model Student
php artisan make:model Facility
##Step 6 Create new controllers
We then create the new controllers in the same fashion. Taking note that Laravel 5.3 officially removes the helper method "controller" that is you no longer can define a controller as
Route::controller('students','StudentController');
Going forward we will then be using resourceful controllers.
Run
php artisan make:controller StudentController --resource
php artisan make:controller CourseController --resource
php artisan make:controller FacilityController --resource
See https://laravel.com/docs/5.3/controllers#resource-controllers for more details
We can then populate the relevant methods on our controllers
##Step 7 Define the routes
Now that we have the new controllers defined, we can add the new routes. The new routes file can be found in the *routes/web.php" file as opposed to the previous "app/Http/routes.php" file.
Your new routes/web.php file should look like.
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
Route::get('/',function(){
return Redirect::to('/home');
});
Auth::routes();
Route::resource('students','StudentController');
Route::resource('courses','CoursesController');
Route::resource('facilities','FacilityController');
Route::get('/home', 'HomeController@index');
##Step 8 Migrating the views.
We now need to make sure that the needed views are available. Let us start by downloading the various available views.
Once we have them on our machine. Once more we extract and upload them to the resources/views folder
The add forms actions need to be changed such that the word "add" is no longer there. Eg for students.
action = "students/add"
to
action = "students"
This is to keep compatibility with resourceful controllers nomenclature.
The files affected are:
- new_student.blade.php
- new_facility.blade.php
- new_course.blade.php
##Step 9 Migrate controller functionality
Migrating controller functionality is where the work will lay.
Based on resourceful controllers
See https://laravel.com/docs/5.3/controllers#resource-controllers for more details
We will transfer the content. For StudentsController we will have
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App;
use Redirect;
class StudentController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('students',['students'=>App\Student::paginate(10)]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('new_student');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$student = new App\Student();
$student->name= $request->get('name');
$student->email= $request->get('email');
$student->course= $request->get('course');
$student->save();
//Once saved redirect back to all students table
return Redirect::to('/students/all');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$student=App\Student::findOrFail($id);
return view('edit_student',['student'=>$student]);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$student=App\Student::findOrFail($id);
$student->name= $request->get('name');
$student->email= $request->get('email');
$student->course= $request->get('course');
$student->save();
return Redirect::to('/students');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
From here we can now create the resources as need be.


