Find us on facebook

Showing posts with label laravel. Show all posts
Showing posts with label laravel. Show all posts

Nov 25, 2018

Move laravel models to Models folder

1. Move the files to the Models folder

2. Change the namespace of the models

Change :

namespace App;

to

namespace App\Models;

3. Change the other files

Search for app\User and change

    app/Http/Controllers/Auth/RegisterController.php
    config/auth.php
    config/services.php
    database/factories/ModelFactory.php
    database/factories/UserFactory.php
    All Controllers

And change App/ModelTest to App/Models/ModelTest

4. Run composer dump-autoload

Feb 1, 2018

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (S QL: alter table `users` add unique `users_email_unique`(`email`)) laravel

namespace App\Providers;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }

Jan 31, 2018

Retrieve nearest drivers - query- laravel mysql

$results = \DB::select(DB::raw('SELECT id, ( 3959 * acos( cos( radians(' . $order->delivery_lattitude . ') ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(' . $order->delivery_logitude . ') ) + sin( radians(' . $order->delivery_lattitude . ') ) * sin( radians(lat) ) ) ) AS distance FROM rider_location HAVING distance < ' . $distance . ' ORDER BY distance'));

Laravel permissions for setup project ubuntu

sudo chgrp -R www-data /var/www/html/project

sudo chmod -R 775 /var/www/html/project/storage

Laravel 5.6 create project

Issue : laravel/framework v5.5.17 requires ext-mbstring * - missing mbstring
Fix : sudo apt install php7.2-mbstring

Issue :  phpunit/phpunit 6.5.5 requires ext-dom *
Fix : sudo apt-get install php7.2-xml

Apr 27, 2015

Laravel5 - Lesson 1

update route.php

Route::get('about', 'PagesController@about');

Browser access URL -> http://localhost/laravel/BATransfer/public/about

Create PagesController

In CLI type

D:\wamp\www\laravel\BATransfer>php artisan make:controller PagesController --plain

app/Http/Controllers/PagesController.php

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Repositories\UserRepository;

class PagesController extends Controller {

public function about(UserRepository $user_gestion){
$users = $user_gestion->index();
return view('pages.about')->with("allUsers", $users);
}

}

app/Models/User

<?php namespace App\Models;
etc....

Create repository

app/Repositories/UserRepository

<?php namespace App\Repositories;
use App\Models\User;

class UserRepository extends BaseRepository {

/**
* Create a new CommentRepository instance.
*
* @param  App\Models\Comment $comment
* @return void
*/
public function __construct(User $user)
{
$this->model = $user;
}


/**
* Get comments collection.
*
* @param  int  $n
* @return Illuminate\Support\Collection
*/
public function index()
{
return $this->model->all();


}
}

resources/views/pages/about.blade.php

<table>
<tr>
<td>ID</td>
<td>Name</td>
</tr>

@foreach($allUsers as $usr)

<tr>
<td>{{ $usr->id }}</td>
<td>{{ $usr->name }}</td>
</tr>

@endforeach
</table>





Apr 26, 2015

Composer

Update

To update all packages

php composer.phar update

To update specific packages

php composer.phar update laravel/framework laravelcollective/html

To install current dependencies on composer.json(read this file and install) into vendor folder

php composer.phar install

Using laravelcollective/html Package in laravel 5

Add following code to composer.json
"require": {
"laravelcollective/html": "5.0.*"
},

Install composer into project folder

In CLI type following command and hit enter

php composer.phar update laravelcollective/html

In config/app.php add following

'providers' => [
    // ...
    'Collective\Html\HtmlServiceProvider',
    // ...
  ],

'aliases' => [
    // ...
      'Form' => 'Collective\Html\FormFacade',
      'Html' => 'Collective\Html\HtmlFacade',
    // ...
  ],


[PDOException] SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin g password: YES) - Error

[PDOException]
  SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin
  g password: YES)

If above error comes when you run D:\wamp\www\laravel\BATransfer>php artisan migrate
command, That means you have not configured .env file at root directory. There you need to set

DB_HOST=localhost
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

and save it. Then run the above command in CLI. Tables will be created.

Installing Composer And Installing Laravel 5 (Method 2)

Download composer to any location you want. You can use following command.

D:\wamp\www>php -r "readfile('https://getcomposer.org/installer');" | php -- --i
nstall-dir=composer

Composer is a directory under www folder. We are going to install composer into that directory.

Following screenshot will give you more detailed idea.


After doing this process you will see that you have composer.phar inside the composer folder.

To install laravel use the following command and hit enter.

D:\wamp\www\composer>php composer.phar create-project laravel/laravel D:/wamp/www/laravel

/BATransfer123 --prefer-dist

Following screenshot will provide more details.


You are Done. :D

Installing Composer And Installing Laravel 5

Installing Composer

Before you install you need to enable php_openssl in php.ini file. Normally if you enable this on WAMP server,


It will uncomment php_openssl in D:/wamp/bin/apache/apache2.2.22/bin/php.ini file. But we need to uncomment D:/wamp/bin/php/php5.4.3/php.ini file to install composer. So manually uncomment the line extension=php_openssl.dll

Then;

You can download composer for windows from following link
https://getcomposer.org/download/
Under Windows Installer click on Composer-Setup.exe to download and then run.

Or you can use following command in CLI
php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

To run php command under any folder in CLI you need to set environment variable. (PHP exe file path)
Eg: D:\wamp\bin\php\php5.4.3

Then restart the computer and open cmd, Then just type php and check.

C:\>php (If no error message displays, then your environment variable has set.

To check whether composer installed correctly you can type just "composer" and hit enter.(You need to go to composer installed folder)

Detailed screenshot shown below.


Installing Laravel 5

Now you have installed composer. Now create folder called laravel (Or any name) under www root folder and in cmd go to the location you have installed the composer and type following command and hit enter. It will create laravel 5 project called BATransfer (Instead this name you can use any name you prefer for your project)

C:\ProgramData\ComposerSetup\bin>composer create-project laravel/laravel D:/wamp
/www/laravel/BATransfer --prefer-dist

You can see detailed screenshot below.


After you install laravel successfully, You can see following folder structure under your directory.


You can access your laravel home page through following URL in localhost.

http://localhost/laravel/BATransfer/public/

That's all :D