Dev-Notes: Exploring Laravel 5 PHP Framework
- To install the Laravel application
Create a folder under C:\Wamp\www\Application1
Go to Application1 folder
Type in
composer create-project laravel/laravel --prefer-dist
- To run PHP artisan in Windows
Run a command line into the Laravel project in this case C:\WAMP\www\xxx\laravel
PHP artisan –help
- Database configuration
/.env
- Fix CORS temp
Add the following code in the top of /bootstrap/app.php
// allow origin
header(‘Access-Control-Allow-Origin: *’);
header(‘Access-Control-Allow-Methods: POST, GET, OPTIONS’);
// add any additional headers you need to support here
header(‘Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept’);
- Database migration
Run:
php artisan migrate
To roll back, run:
php artisan migrate:rollback
Sometimes when try rollback, it has Class XXX not found. Run:
composer dumpautoload
- Test the model via Tinker
To run:
php artisan tinker
>>> $programActivityItem = App\ProgramActivityItem::where('uuid', '0848e01e-9cc0-11e5-b3a2-00ffc9587cbc')->first(); >>> $programActivityItem = new App\ProgramActivityItem();
- Passing variable from Controller to View in 3 ways:
Controller:
class ProfileController extends Controller {
$name = “Aaron”;
return view(‘profile’)->with(‘namep’m $name);
}
View (profile.blade.php)
This profile of {{ namep }}
Controller:
class ProfileController extends Controller {
$name = “Aaron”;
$age = 80;
return view(‘profile’)->with([
‘namep’ =>$name,
‘agep’ => $age
]
);
}
View (profile.blade.php)
This profile of {{ namep }}
Controller:
class ProfileController extends Controller {
$data[‘name’] = “Aaron”;
$data[‘age’] = 80;
return view(‘profile’)->with(‘datap’, $data);
}
View (profile.blade.php)
This profile of {{ $datap[‘name’] }} and age is {{ $datap[‘age’] }}
Controller:
class ProfileController extends Controller {
$name = “Aaron”;
$age = 80;
return view(‘profile’)->with(‘datap’, compact(‘name’, ‘age’));
}
View (profile.blade.php)
This profile of {{ $data[‘name’] }} and age is {{ $data[‘age’] }}
Deploying
GoDaddy Shared Hosting
See the resource link.
To find the hosting path, check out the left hand side – Absolute Hosting Path (/home/content/31/8072431/html)
Azure
See the resource below.
Challenges
- When deploying the Ionic into production, turn out that the drop-down list selected item is not working properly however the development working well. You might think that it’s something to do with the Ionic View version but turn out that due database configuration issue so it needs to have the show() method:
return response()->json($user, 200, [], JSON_NUMERIC_CHECK);
This will force to have no double quote in json for the integer value.
- local.ERROR: exception ‘Illuminate\Session\TokenMismatchException’ in C:\wamp\www\practiceMobileLaravelApp-dev\laravel\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php:53
After intensive research and trial and error, the temp solution is to bypass this in this
class VerifyCsrfToken extends BaseVerifier
of /app/http/Middleware/VerifyCsrfToken.php
protected function shouldPassThrough($request) { foreach ($this->except as $except) { if ($request->is($except) || str_contains($request->url(), $except)) { return true; } } return false; }
- Fatal error: Uncaught exception ‘ReflectionException’ with message ‘Class log does not exist’
After adding a custom error based on this blog https://blog.muya.co.ke/configure-custom-logging-in-laravel-5/ , the web app is not working anymore on throwing that error when you run php artisan return.
The solution is to run “composer dumpautoload” in the command line within the app directory due to there being a change on composer.json based on the blog above.
Resources
- Error on “Whoops, looks like something went wrong” with new installation – http://laravel.io/forum/04-22-2014-whoops-looks-like-something-went-wrong-with-new-installation
- Laravel 5 on Azure – http://laravel.io/forum/04-05-2015-howto-laravel-5-on-microsoft-azure
- Laravel installation on shared GoDaddy hosting 1 of 2 – https://www.youtube.com/watch?v=MwkBh5uJPKA
- Laravel installation on shared GoDaddy hosting 2 of 2 – https://www.youtube.com/watch?v=0ZNaiHMB22I
- Deploying Laravel 5 into GoDaddy Shared Hosting – https://medium.com/@kunalnagar/deploying-laravel-5-on-godaddy-shared-hosting-888ec96f64cd#.jl44ry41b
- Laravel custom logging – https://blog.muya.co.ke/configure-custom-logging-in-laravel-5/
- Belajar Laravel 5 dari Sekolah Koding – https://www.youtube.com/watch?v=rJBoxq9UsLM&list=PLCZlgfAG0GXDlNd0Flz20xksNtJQZWywz
- Token-Based Authentication for Angular JS and Laravel – https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps
Credits
Photo by Nimit Kansagra: https://www.pexels.com/photo/illuminated-computer-screen-4509131/
[Note: Pageviews – 1,317 – before migrated from the Dewalist Blog website on 09/08/2020]