Stay Tuned!

Subscribe to our newsletter to get our newest articles instantly!

Programming

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




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]