mercredi 28 février 2018

What todo when composer update and composer install give error ?

I run composer install I got this error, telling me to use composer update

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for doctrine/inflector v1.3.0 -> satisfiable by doctrine/inflector[v1.3.0].
    - doctrine/inflector v1.3.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 2
    - Installation request for symfony/css-selector v4.0.3 -> satisfiable by symfony/css-selector[v4.0.3].
    - symfony/css-selector v4.0.3 requires php ^7.1.3 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 3
    - Installation request for symfony/event-dispatcher v4.0.3 -> satisfiable by symfony/event-dispatcher[v4.0.3].
    - symfony/event-dispatcher v4.0.3 requires php ^7.1.3 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 4
    - Installation request for doctrine/instantiator 1.1.0 -> satisfiable by doctrine/instantiator[1.1.0].
    - doctrine/instantiator 1.1.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 5
    - doctrine/inflector v1.3.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - laravel/framework v5.5.32 requires doctrine/inflector ~1.1 -> satisfiable by doctrine/inflector[v1.3.0].
    - Installation request for laravel/framework v5.5.32 -> satisfiable by laravel/framework[v5.5.32].

I run composer update, I got this

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - doctrine/dbal v2.6.3 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - doctrine/dbal v2.6.2 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - doctrine/dbal v2.6.1 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - doctrine/dbal v2.6.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - Installation request for doctrine/dbal ^2.6 -> satisfiable by doctrine/dbal[v2.6.0, v2.6.1, v2.6.2, v2.6.3].

Now what should I do ?

This is what I have in composer.json

cat composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "anouar/paypalpayment": ">=3.0",
        "doctrine/dbal": "^2.6",
        "fideloper/proxy": "~3.3",
        "guzzlehttp/guzzle": "^6.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "spatie/laravel-newsletter": "^4.1",
        "srmklive/paypal": "~1.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~6.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "files": ["app/Http/Helper.php"]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
} 



via Chebli Mohamed

How to autofill Edit form with old Information from two different tables?

I have this form "Edit tache". Editing one "tache" affects two tables user and technicien, when i choose to edit tache the edit form is autofilled with information from the technicien table but the fields related to the table user are not autofilled. How could i autofill the form with information from the two tables? Thank you.

enter image description here

controller

public function edit($id)
{
    $technicien=technicien::find($id);
    $user = user::orderBy('id', 'asc')->get();
    return view('technicien.edit',['moyenne_avis'=>$technicien],['actif'=>$technicien],['user_id'=>$technicien])->with('users', $user );
}

public function update(Request $request, $id)
{
    // do some request validation
    $technicien=technicien::find($id);
    $technicien->update($request->all());
    return redirect('technicien');
}

View

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Modifier Tache</h1>
        <form action="" method="post">
        
        


            <div class="form-group">
                <label for="">Nom</label>
                <input id="nom" type="text" class="form-control" name="nom" value="" required autofocus>
            </div>
            <div class="form-group">
                <label for="">Prenom</label>
                <input id="nom" type="text" class="form-control" name="nom" value="" required autofocus>
            </div>

            <div class="form-group">
                <label for="">moyenne Avis</label>
                <input type="text"  name ="moyenne_avis" class="form-control"value ="" >
            </div>
            <div class="form-group">
                <label for="">Etat Technicien</label>
                <input type="text"  name ="actif" class="form-control"value ="" >
            </div>



            <div class="form-group">

                <input type="submit" value = "enregistrer" class="form-control btn btn-primary">
            </div>
        </form>
    </div>
</div>
@endsection

route

Route::get('/technicien/{id}/edit', 'TechnicienController@edit');
Route::put('/technicien/{id}', 'TechnicienController@update')-
>name('technicien.update');



via Chebli Mohamed

How to autofill Edit form with old Information of a user?

i have this form "Modifier Technicien" with which I will modify the information of a technician, the modifications will affect two tables of my database table user and table technician. I want my form to be autofilled with the information of the technician I chose to modify. Thank you

enter image description here

edit.blade.php

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Modifier Technicien</h1>
        <form action="" method="post">
        
        



          <div class="form-group">
                <label for="">Nom</label>
                <input id="nom" type="text" class="form-control" name="nom" value="" required autofocus>

                            @if ($errors->has('nom'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
            </div>
            <div class="form-group">
                <label for="">Prenom</label>
                <input id="prenom" type="text" class="form-control" name="prenom" value="" required autofocus>

                            @if ($errors->has('prenom'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
            </div>
            <div class="form-group">
                <label for="">Telephone</label>
                <input id="tel" type="text" class="form-control" name="tel" value="" required autofocus>

                            @if ($errors->has('tel'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
            </div>
            <div class="form-group">
                <label for="">Mobile</label>
                <input id="mobil" type="text" class="form-control" name="mobil" value="" required autofocus>

                            @if ($errors->has('mobile'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
            </div>
            <div class="form-group">
                <label for="">Role</label>
                <input id="role" type="text" class="form-control" name="role" value="" required autofocus>

                            @if ($errors->has('role'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
            </div>



            <div class="form-group">
                <label for="">Moyenne Avis</label>
                <input type="text"  name ="moyenne_avis" class="form-control"value="">
            </div>
            <div class="form-group">
                <div class="form-group">
                <label for="">Etat</label>
                <input type="text"  name ="actif" class="form-control"value="">
            </div>




            <div class="form-group">

                <input type="submit" value = "enregistrer" class="form-control btn btn-primary">
            </div>
        </form>
    </div>
</div>
@endsection

controller

public function edit($id)
{
    $technicien=technicien::find($id);
    $users = user::orderBy('id', 'asc')->get();
    return view('technicien.edit',['moyenne_avis'=>$technicien],['actif'=>$technicien],['user_id'=>$technicien])->with('user', $users);
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
     technicien::where('id', $id)->update($request->all());
     return redirect('technicien/edit');
}

route.php

Route::get('/technicien/{id}/edit', 'TechnicienController@edit');
Route::put('/technicien/{id}', 'TechnicienController@update')-
>name('technicien.update');



via Chebli Mohamed

Multiple jobs are processing with one worker

I have an app built on laravel 5.1 which is using RabbitMQ for job processing. The worker command is as follows:

php artisan queue:work --queue=[queue-name] --daemon --tries=5

The issue which I am experiencing is that multiple jobs are getting processed at the same time even though I have only one worker for the queue. How and why is this happening? I have a table which tracks the status of the jobs and as per the table, the number of parallel processing jobs sometimes increase to 8 or 9. With one worker, this count is strange.

Note:

  • My application has 3500-4000 jobs for processing daily
  • The jobs are time consuming so dont know if this has something to do with the process timeout


via Chebli Mohamed

mardi 27 février 2018

Instagram Integration on Laravel 5

I kept getting this issue after installing this package below

https://github.com/vinkla/instagram

into my Laravel 5.1 project.

2018-02-27 at 1 55 36 pm

I followed everything in the instruction.

I am on Mac OS X, PHP 7.1, Laravel 5.1

Did I forget something?

How would one go about and debug this further ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!



via Chebli Mohamed

How to make a dropdown list suggest only options in relation with a selected value?

In my form below i have two dropdown lists the first one to choose "metier" and a second one to choose "tache" when i choose a "metier" i want that the second dropdown list "tache" suggest only options in relation with the already selected "Metier". Could anyone help me with this please.

enter image description here

create.blade.php

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
@if(count($errors))
<link rel="stylesheet" 
href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script    src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">

 <div class="alert alert-danger" role="alert">
 <ul>
    @foreach($errors ->all() as $message)
     <li></li>
        @endforeach
 </ul>
</div>
@endif
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Tarification tache</h1>
        <form action=" " method="post">
         

            <div class="form-group">
                <label for="technicien">Technicien</label>
                <select name="technicien_id" id="technicien" class="form-control" >

                        @foreach($techniciens as $techniciens)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>
////////////
            
            <div class="form-group">
                <label for="metier">Libelle metier</label>
                <select name="metier" id="metier" class="form-control">

                        @foreach($metiers as $metier)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>

            <div class="form-group">
                <label for="Tache">Libelle Tache</label>
                <select name="tache" id="Tache" class="form-control">

                        @foreach($taches as $tache)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>
            

//////////////
            <div class="form-group">
                <label for="">Tarif</label>
                <input type="text"  name ="Tarif" class="form-control"value="">
            </div>
            <div class="form-group">
                <input type="submit" value = "enregistrer" class="form-control btn btn-primary">
            </div>
        </form>
    </div>
</div>


<script>
    $('#metier').on('change',function(e){
        console.long(e);
        var met_id = e.target.value;

        $.get('/ajax-tac?met_id=' + met_id, function(data){
            $('#tache').empty();
            $.each(data,function(index, tacObj){
                $('#tache').append('<option value="'+tacObj.id+'">'+catObj.libelle_tache+'</option>');
            });

        });

    });
</script>

@endsection

route.php

Route::get('/tarification', 'TarificationController@index');
Route::get('/tarification/create', 'TarificationController@create');
Route::post('/tarification', 'TarificationController@store');
Route::get('/tarification/{id}/edit', 'TarificationController@edit');
Route::put('/tarification/{id}', 'TarificationController@update');
Route::delete('/tarification/{id}', 'TarificationController@destroy');

Route::get('/ajax-metier',function(){
        $met_id = Input::get('met_id');
        $taches = tache::where('metier_id','=', $met_id)->get();
        return Response::json($metiers);
});

controller

public function create()
{
    $techniciens = technicien::orderBy('id','desc')->get();
    $taches = Tache::orderBy('libelle_tache', 'asc')->get();
    $metiers = Metier::all();
    return view('tarification.create')->with('taches', $taches)->with('techniciens', $techniciens)->with('metiers', $metiers);
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    $tarification = new tarificationtache();

    $tarification ->tache_id = $request->input('tache_id');
    $tarification ->Tarif =$request->input('Tarif');
    $tarification->save();
    $tarification->techniciens()->attach($request->technicien_id);
    return redirect('home');
}



via Chebli Mohamed

Timeout value in case of queue:work

I have an app built on laravel 5.1 which is using RabbitMQ for job processing. The worker command is as follows:

php artisan queue:work --queue=[queue-name] --daemon --tries=5

What is the default timeout value in case of queue:work?

Also, if timeout is set via "set_time_limit" within a job and queue:work has its own timeout lets say 60 seconds, how the job processing is affected? What are the impacts on this conflicting timeouts?



via Chebli Mohamed

how to autofill a form field with only the "tâches" in relation with the chosen "Metier"?

I have this form and then I have in my database a set of "taches" that is linked to each "metier", I want to choose a "metier" in the field and the following field "taches" to propose me to choose only "taches" related to this "metier". Here is my code and my form.I would be very grateful if someone could help me with this.

create.blade.php

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
@if(count($errors))
<link rel="stylesheet" 

href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>


<div class="alert alert-danger" role="alert">
 <ul>
    @foreach($errors ->all() as $message)
     <li></li>
        @endforeach
 </ul>
</div>
@endif
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Tarification tache</h1>
        <form action=" " method="post">
         

            <div class="form-group">
                <label for="technicien">Technicien</label>
                <select name="technicien_id" id="technicien" class="form-control" >

                        @foreach($techniciens as $techniciens)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>
 ////////////
            
            <div class="form-group">
                <label for="metier">Libelle metier</label>
                <select name="metier" id="metier" class="form-
 control">

                        @foreach($metiers as $metier)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>

            <div class="form-group">
                <label for="Tache">Libelle Tache</label>
                <select name="tache" id="Tache" class="form-control">

                        @foreach($taches as $tache)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>
            

       //////////////
            <div class="form-group">
                <label for="">Tarif</label>
                <input type="text"  name ="Tarif" class="form-control"value="">
            </div>
            <div class="form-group">
                <input type="submit" value = "enregistrer" class="form-control btn btn-primary">
            </div>
        </form>
    </div>
</div>


<script>
    $('#metier').on('change',function(e){
        console.long(e);
        var met_id = e.target.value;

        $.get('/ajax-tac?met_id=' + met_id, function(data){
            $('#tache').empty();
            $.each(data,function(index, tacObj){
                $('#tache').append('<option value="'+tacObj.id+'">'+catObj.libelle_tache+'</option>');
            });

        });

    });
</script>

@endsection

route.php

Route::get('/tarification', 'TarificationController@index');
Route::get('/tarification/create', 'TarificationController@create');
Route::post('/tarification', 'TarificationController@store');
Route::get('/tarification/{id}/edit', 'TarificationController@edit');
Route::put('/tarification/{id}', 'TarificationController@update');
Route::delete('/tarification/{id}', 'TarificationController@destroy');

Route::get('/ajax-metier',function(){
        $met_id = Input::get('met_id');
        $taches = tache::where('metier_id','=', $met_id)->get();
        return Response::json($metiers);
});

controller

public function create()
{
    $techniciens = technicien::orderBy('id','desc')->get();
    $taches = Tache::orderBy('libelle_tache', 'asc')->get();
    $metiers = Metier::all();
    return view('tarification.create')->with('taches', $taches)->with('techniciens', $techniciens)->with('metiers', $metiers);
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    $tarification = new tarificationtache();

    $tarification ->tache_id = $request->input('tache_id');
    $tarification ->Tarif =$request->input('Tarif');
    $tarification->save();
    $tarification->techniciens()->attach($request->technicien_id);
    return redirect('home');
}



via Chebli Mohamed

Issue connecting custom queue driver laravel 5.1 'No connector for [mysql]'

I have searched the query all over internet but till have not come up to the solution for this issue. No connector for [mysql]

I have 2 Mysql Connections mysql and mysql2. mysql is to store data and mysql2 to store QUEUE JOBS.

Here below is the .ENV file details.

 DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=laravel_5_1
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=mysql_queue

As you can see the about connection is DB_CONNECTION=mysql and my Queue driver QUEUE_DRIVER=mysql_queue

I have assigned and new queue driver named mysql_queue in queue.php

below is the queue.php code

 'default' => env('QUEUE_DRIVER', 'mysql_queue'),

'connections' => [
'mysql_queue' => [
            'connection' => 'mysql2',
            'driver' => 'mysql',
            'table' => 'jobs',
            'queue' => 'default',
            'expire' => 60,
        ],
]

'failed' => [
        'database' => env('DB_CONNECTION', 'mysql_queue'),
        'table' => 'failed_jobs',
    ],

As you can see the mysql_queue has 'connection' => 'mysql2', were i would like to store queued jobs. mysql2 is a new connection assiged in database.php below is the code.

'mysql2' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'laravel_5_1_queue'),
        'username'  => env('DB_USERNAME', 'root'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ], 

Even after making these major changes as per laravel documentation i still get 'No connector for [mysql]' Error and unable to run QUEUED JOBS in background. kindly suggest me.

Thanks in Advance



via Chebli Mohamed

dimanche 25 février 2018

include a class from a different website in laravel new project

I am working on a backend api using laravel 5.6 Already have a website with tons of code - all the answers I found point at create a new folder and adding my classes there that is not an option. I would like to include the class from the main site (same server) and use the methods within laravel to generate the data from the api.

 Route::get('api/author/full/', array('uses' => 'AuthorController@getAuthor'));

I am using this line to include my class:

require_once('/var/www/html/modules/author/models/Author.class.php');

laravel is located in a subfolder at /var/www/html/api/

this is the error I get when i try to require that file from within the AuthorController :

 Fatal error: Call to undefined method ErrorException::getStatusCode() in  /html/api/app/Exceptions/Handler.php on line 61

Fatal error: Call to undefined method Symfony\Component\Debug\Exception\FatalErrorException::getStatusCode() in  /html/api/app/Exceptions/Handler.php on line 61

really tried everything here,included it in public/index.php and in other places and none of these things worked.



via Chebli Mohamed

new “Metier” is created when editing a “Metier ”

when I try to edit a "Metier", a new "Metier" is created and the old one stays the same. I want to crush the old "Metier" and create a new one just by editing. Could anyone help me with this please ?

Controller

 public function edit($id)
{
$metier=Metier::find($id);
return view('metier.edit',['libelle_metier'=>$metier]);
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
 public function update(Request $request, $id)
{
$metier=Metier::find($id);
return view('metier.edit',['libelle_metier'=>$metier]);
}

View

 <div class="form-group">
 <label for="">libelle Metier </label>
 <input type="text"  name ="libelle_metier" class="form-control"value ="
 " >
 </div>

 <div class="form-group">
 <input type="submit" value = "enregistrer" class="form-control btn btn-
 primary">
 </div>

route

Route::get('/metier', 'MetierController@index');
Route::get('/metier/create', 'MetierController@create');
Route::post('/metier', 'MetierController@store');
Route::get('/metier/{id}/show', 'MetierController@edit');
Route::get('/metier/{id}/edit', 'MetierController@edit');
Route::upd('/metier/{id}/update', 'MetierController@update');
Route::delete('/metier/{id}', 'MetierController@destroy')



via Chebli Mohamed

mercredi 21 février 2018

Laravel 5.1 Mail::queue Amazon SQS error 404

I first encountered with queue services (in that case it Amazon SQS). I configure queue.php and tried to send mail like that:

\Mail::queue('emails.reminder', [], function($message){
    $message->to('xxxxxxx@gmail.com', 'XXX')->subject('XXX');
});

But I have an error:

Error executing "SendMessage" on "https://sqs.eu-central-1.amazonaws.com/EmailQueue"; AWS HTTP error: Client error: `POST https://sqs.eu-central-1.amazonaws.com/EmailQueue` resulted in a `404 Not Found` response:
<?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>I (truncated...)
InvalidAddress (client): The address /EmailQueue is not valid for this endpoint. - <?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>InvalidAddress</Code><Message>The address /EmailQueue is not valid for this endpoint.</Message><Detail/></Error><RequestId>72ea954e-eaf4-55b8-96bb-c6499a1e4015</RequestId></ErrorResponse>

Can anyone help me?

Thanks!



via Chebli Mohamed

lundi 19 février 2018

Laravel 5.1 Blade (or just plain echo) displaying classes incorrectly

I have the following code in my Laravel (5.1) view. The code in the PHP block decides which class I should apply to the first td element below.

@foreach($datesUnavailable as $dateUnavailable)
    <?php
        $unavailableDate = strtotime($dateUnavailable->unavailable_on);
        $creationDate = strtotime($dateUnavailable->created_at);
        $newformat = date('D, M d, Y',$unavailableDate);

        $createdBefore = ($unavailableDate - $creationDate)/86400;

        if($createdBefore >= 5) {
            $class = "alert alert-success";                                           
        } else if ($createdBefore < 5 && $createdBefore >= 3) {
            $class = "alert alert-warning"; 
        } else {
            $class = "alert alert-danger";
        }
    ?>
    <tr>
        <td class=></td>
        <td></td>
        <td>
            {!! Form::open([
                'method' => 'DELETE',
                'route' => ['delete-unavailability', $alias, $dateUnavailable->uc_key],
                'onsubmit' => 'return submitResult();'
            ]) !!}
                {!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs']) !!}
            {!! Form::close() !!}
        </td>
    </tr>
@endforeach

However, when the page renders, the classes on the td element show as

<td class="alert" alert-success="">Wed, Feb 28, 2018</td>

That is, I want it to show class="alert alert-success" (based on the logic) but it displays this weird string. If I do a var_dump($class), I see the value of the $class variable as "alert alert-success".

Any idea why this might be happening?



via Chebli Mohamed

jeudi 15 février 2018

How login with Facebook and Google without authentication in Laravel 5.1 using socialite version 2.1?

'facebook' => ['client_id' => 'id',
'client_secret' => 'fgdfgsdfgrtt45453',
'redirect' => 'http://example.com/callback', ],

In route.php

Route::get('/redirect', 'SocialAuthFacebookController@redirect'); Route::get('/callback', 'SocialAuthFacebookController@callback');

And I have add Services/SocialFacebookAccountService.php directory in App. SocialFacebookAccountService.php

namespace App\Services;
use App\SocialFacebookAccount;
use App\User;
use Laravel\Socialite\Contracts\User as ProviderUser;

class SocialFacebookAccountService
{
    public function createOrGetUser(ProviderUser $providerUser)
    {
        $account = SocialFacebookAccount::whereProvider('facebook')
            ->whereProviderUserId($providerUser->getId())
            ->first();
        echo 'Account info : ';

        if ($account) {
            return $account->user;
        } else {

            $account = new SocialFacebookAccount([
                'provider_user_id' => $providerUser->getId(),
                'provider' => 'facebook'
            ]);

            $user = User::whereEmail($providerUser->getEmail())->first();

            if (!$user) {

                $user = User::create([
                    'email' => $providerUser->getEmail(),
                    'name' => $providerUser->getName(),
                    'password' => md5(rand(1,10000)),
                ]);
            }

            $account->user()->associate($user);
            $account->save();

            return $user;
        }
    }
}

Please help , How to get user info in callback.



via Chebli Mohamed

mardi 13 février 2018

Laravel 5.1 - retrieving a polymorphic association with WHERE clause

I'm having trouble retrieving a polymorphic association "where related_object.column_name = x". Let me explain:

I have a number of “pages" in my database, and each page has polymorphic association to different types of “content”. for example :

pages

slug : my-page, id : 1

slug : my-other page, id: 2

music_track table

music_track : id 10, page_id : 1

video table

video : id 20, page_id: 2

image table

image : id 30, page_id: 1

content table

id: 555, contentable_id 10, contentable_type: App\music_track

id: 556, contentable_id 20, contentable_type: App\video

id: 557, contentable_id 30, contentable_type: App\image

I can return all content using Content::all( ), how do I return all content who’s page_id is ‘1’?

I can't seem to use Content::where('page_id', "=", "1"), because page_id is ambiguous, or assumed to be part of the content table. How to a query the RELATED table?



via Chebli Mohamed

Laravel TokenMismatch for one user only, possible reasons

Bugsnag has been reporting a single user keeps receiving a TokenMismatchException throughout the last few weeks on my production Laravel 5.1 environment, no other user has experienced this issue.

Stacktrace

The exception trace

Request Data (Obscured)

Request data

I considered perhaps the session was dying for this particular user, that they spent too long idle on the login page however I noticed sometimes they make 2 or 3 attempts in quick succession.

I'm preparing to contact the user but wish to understand the possibilities of why this exception keeps occurring other than a genuine attack before I do.



via Chebli Mohamed

vendredi 9 février 2018

How to create an error page to a QueryException?

I'm working on a commercial application and I've created Blade files for several kinds of HTTP errors. They are placed in /resources/views/errors and are working fine for authorization (503.blade.php), page not found (404.blade.php), and so on.

I've created files for 400, 403, 404, 500 and 503, until now. The issue is when a QueryException is thrown. In this case, "Whoops, looks like something went wrong." appears.

For example, considering that name cannot be null, when I do something like this, Laravel throws a QueryException:

User::create([
          'name' => null,
          'email' => 'some@email.com'
]);

The exception would be:

QueryException in Connection.php line 651: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into users (nome, email, updated_at, created_at) values (, some@email.com, 2018-02-09 12:10:50, 2018-02-09 12:10:50))

I don't want "Whoops, looks like something went wrong." to appear to the end user, I want to show a custom page. What kind of error file do I need to create to achieve this behavior?



via Chebli Mohamed

Installing Omnipay/payu with laravel 5.1

I am developing a website using Laravel 5.1 and i need to have a shopping cart set up, i am trying to install Omnipay for this, i have selected three gateways i will be using: Paypal, Stripe and PayU. My require under composer.json looks like this:

"require": {
    ...
    "ignited/laravel-omnipay": "2.*",        
    "omnipay/paypal": "*",
    "omnipay/stripe": "*",
    "omnipay/payu": "*"
},

And i am getting error on the payu part alone, this is the error:

The requested package omnipay/payu * is satisfiable by omnipay/payu[dev-master, 2.0.x-dev] but these conflict with your requirements or minimum-stability.

I read on another post that specifying "prefer-stable": true, and "minimum-stability": "dev" into the config part of the composer.json would fix the issue but its not working for me, any tips?



via Chebli Mohamed

dimanche 4 février 2018

Duplicate Oracle Sequence

I have a problem about using oracle sequence with yajra/laravel-oci8 library (v.5.1) in Laravel 5.1.

My scenario are:

  1. I have a column named trailer_id in table A.
  2. That column contain ID that generated using sequence named trailed_id_seq. Code:

    function postCreate(Request $request) {
        $id = $request->input('id');
    
        DB::beginTransaction();
    
        ....
    
        $running_no_seq = DB::getSequence();
        $trailer_id = $running_no_seq->nextValue('trailer_id_seq')."";
    
        for($i=0; $i < $counter; $i++) {
           // Some process, it can take a while here...
        }
    
        DB::table('A')->where('id',$id)->update([
           'trailer_id' => $trailer_id
        ]);
    
        DB::commit();
    }
    
    

    The property of trailer_id_seq sequence (captured in Navicat apps): enter image description here

  3. This function can be called by many users.

The problem is:

Why the trailer_id column can be duplicate when accessed by different user in different time?

Here some example: (created_by is user ID) enter image description here

My question: How is this possible? How can i fixed it? (I can't make trailer_id column to unique)

I've read yajra oci docs: https://yajrabox.com/docs/laravel-oci8/master/sequence , is the code DB::getSequence()->nextValue('seq_name'); ONLY return next value and not updated the sequence?

Because in oracle docs, nextval is increments the sequence and returns the next value (https://docs.oracle.com/cd/A84870_01/doc/server.816/a76989/ch26.htm#4062).

Please help me. Thank you for any answer!



via Chebli Mohamed