Categories
Laravel

How to execute PHP code from the command line?

Simple just type

php -a

More info about php :

Categories
Laravel Valet

How to fix valet ? Laravel Valet – This Site Can’t Be Reached

How to fix ?

NOTICE: [pool valet] ‘user’ directive is ignored when FPM is not running as root

or

ERROR: FPM initialization failed

or

Laravel Valet – This Site Can’t Be Reached

or

valet nginx 137 upstream timed out (60: Operation timed out) while reading response header from upstream, client: 127.0.0.1,

Solution

valet uninstall
rm -rf ~/.valet
rm -rf ~/.config/valet
valet install
valet link
valet open
Categories
Laravel

How to fix Laravel – Declaration of OM\Db::query(string $statement) must be compatible with PDO::query ?

#1 – Remove from composer Json the similar line

“doctrine/dbal”: “^2.10”,

#2 – Run

composer upgrade

#3 – Run

composer update

#4 – Voila ! The error should be fixed !

Categories
Laravel MySql

LARAVEL – auto increment a column with mysql – upsert

see example below of an upsert

Polls::updateOrInsert(['business_id'=> $business_id],
    [
        "$vote_value" => DB::raw('$vote_value + 1'),
        'polls_name' => $theBusiness->BUSINESSNAME,
        'source' => env('APP_CODE'),
        'updated_at' => $lastupdated
    ]);
Categories
Laravel SqLite

SQLITE – Auto-increment a column with Laravel

Example : for SQLITE the double quote is critical to make it work

Polls::updateOrInsert(['business_id'=> $business_id],
    [
        "$vote_value" => DB::raw('"$vote_value" + 1'),
        'polls_name' => $theBusiness->BUSINESSNAME,
        'source' => env('APP_CODE'),
        'updated_at' => $lastupdated
    ]);
Categories
Laravel

Laravel Eloquent SQL query compare insensitive string

'ilike' or 'not ilike'
return $query->where('api_call', 'not ilike', '%TEST%');
Categories
Laravel

Install Css Flag with Laravel

#1 – Install Flag library via NPM

npm install flag-icon-css

#2 – Import css to your library

 import 'flag-icon-css/css/flag-icon.css'

#3 – in your blade

<li >
    <a href="/en"> <i class=" flag-icon flag-icon-us"></i></a>
</li>
Categories
Laravel

Laravel : php artisan migrate specific file

use this command php artisan migrate --path=/database/migrations/my_migration.php 

Categories
Laravel

Laravel : How to cache bust app.js ?

In the following file [webpack.mix.js] look at mix.version();

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */



mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css').version();

mix.version();

Categories
Laravel

Laravel Nova – Quickstart Postgres

Quick resource + model generator

php artisan nova:resource Businesses 
php artisan make:model Businesses

Model Example : Thetable

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Thetable extends Model
{

    protected $connection = 'pgsql-api';
    protected $table = 'mapi_admin_tool.THETABLE';
    
    protected $primaryKey = 'id';

    protected $dateFormat = 'Y-m-d H:i:sO';


   public function __construct(array $attributes = [])
   {
     parent::__construct($attributes);
   }

    protected $dates = [
     'created_at',
     'updated_at',
     'deleted_at'
   ];
}

Nova Resource Example

<?php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

class Thetable extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = 'App\M2TrackFileSubmissionToWindsurfer';

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'id';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id',
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make('id')->sortable(),
            Text::make('file_uuid')->sortable(),
            Text::make('set_uuid')->sortable(),
            Text::make('windsurfer_job_id')->sortable(),
            Text::make('cust_filename')->sortable(),
            Text::make('artwork_info')->sortable(),
            Date::make('created_at')->sortable(),
            Date::make('update_at')->sortable(),
        ];
    }