vendredi 19 janvier 2018

Using a Mailable instead of a MailMessage for password reset emails in Laravel 5.5

I'd like my application to use Mailables for all of the emails it sends, so I created my own ResetPasswordEmail class that extends Mailable. Then I created my own ResetPassword notification class that extends the vendor class of the same name and overrode the toMail method as follows:

public function toMail($notifiable)
{
    return (new ResetPasswordEmail())->with('token', $this->token);
}

Then I overrode the sendPasswordResetNotification from the CanResetPassword trait in my User model like this:

public function sendPasswordResetNotification($token)
{
    $this->notify(new ResetPassword($token));
}

Calling my custom ResetPassword notification class.

The problem is that if I use the default method of creating a MailMessage and sending it, it automatically populates the 'to' field with the user's email. But when I use my ResetPasswordEmail mailable class, it doesn't.

Is there a good way to get it to work like that with my custom mailable?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DrqwPq
via IFTTT

How to include a module in Laravel

I am trying to use ReactPHP in a Laravel 5.5 installation. In a non-laravel project it works fine. I've copied this library to

DOCUMENT_ROOT/vendor/react

The class I'm trying to load is DOCUMENT_ROOT/vendor/react/event-loop/src/Factory.php

I am using absolute referencing rather than using name-spaces - so in my class that uses React I have:

$loop = \React\EventLoop\Factory::create();

Laravel is complaining with:

Class 'React\EventLoop\Factory' not found

How can I get it to load, and is the vendor directory the right place to put it?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DuorBr
via IFTTT

Field 'id' doesn't have a default value for UUID Field in Laravel

I have just started learning laravel. I'm familiar with CakePHP.

I used to use UUID field as primary key in my database and in CakePHP, it was quite simple to just change data type of column field to CHAR(36) and it works well.

In Laravel, I have modified users migration to change increments to uuid field and set to primary key

CreateUserTable

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->uuid('id');
            $table->primary('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });

        Schema::table('users', function (Blueprint $table) {
            $table->string('first_name')->nullable();
            $table->string('last_name')->nullable();
            $table->uuid('role_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

But, when I save a new record, it gives error as

Illuminate\Database\QueryException thrown with message
"SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value 
(SQL: insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) 
values (Anuj, anuj@example.com, password_hash, date-time, date-time))"



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mVs8GY
via IFTTT

Docker: bitbucket pipelines ext-zip *

I'm trying to set up pipelines with Bitbucket for one of the Laravel driven project and I've spent already hours trying to get it to work, but just can't get over the following:

+ composer install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Installation request for facebook/webdriver 1.5.0 -> satisfiable by facebook/webdriver[1.5.0].
    - facebook/webdriver 1.5.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
  Problem 2
    - facebook/webdriver 1.5.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - laravel/dusk v2.0.8 requires facebook/webdriver ~1.0 -> satisfiable by facebook/webdriver[1.5.0].
    - Installation request for laravel/dusk v2.0.8 -> satisfiable by laravel/dusk[v2.0.8].

My config file

image: php:7.2.1

pipelines:
  default:
    - step:
        caches:
          - composer
        script:
          - apt-get update && apt-get install -y unzip
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - apt-get update && apt-get install -qy git curl libmcrypt-dev mysql-client libzip-dev zip
          - docker-php-ext-install mcrypt && docker-php-ext-install pdo_mysql && docker-php-ext-install zip
          - composer install
          - php artisan key:generate
          - export CACHE_DRIVER=redis
          - export SESSION_DRIVER=redis
          - export DB_CONNECTION=mysql
          - vendor/bin/phpunit -c phpunit.xml
        services:
          - mysql

definitions:
  services:
    mysql:
      image: mysql
      environment:
        MYSQL_DATABASE: 'homestead'
        MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
        MYSQL_USER: 'homestead'
        MYSQL_PASSWORD: 'secret'

Does anyone know what might be causing it?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DtjtF1
via IFTTT

Docker: bitbucket pipelines ext-zip *

I'm trying to set up pipelines with Bitbucket for one of the Laravel driven project and I've spent already hours trying to get it to work, but just can't get over the following:

+ composer install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Installation request for facebook/webdriver 1.5.0 -> satisfiable by facebook/webdriver[1.5.0].
    - facebook/webdriver 1.5.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
  Problem 2
    - facebook/webdriver 1.5.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - laravel/dusk v2.0.8 requires facebook/webdriver ~1.0 -> satisfiable by facebook/webdriver[1.5.0].
    - Installation request for laravel/dusk v2.0.8 -> satisfiable by laravel/dusk[v2.0.8].

My config file

image: php:7.2.1

pipelines:
  default:
    - step:
        caches:
          - composer
        script:
          - apt-get update && apt-get install -y unzip
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - apt-get update && apt-get install -qy git curl libmcrypt-dev mysql-client libzip-dev zip
          - docker-php-ext-install mcrypt && docker-php-ext-install pdo_mysql && docker-php-ext-install zip
          - composer install
          - php artisan key:generate
          - export CACHE_DRIVER=redis
          - export SESSION_DRIVER=redis
          - export DB_CONNECTION=mysql
          - vendor/bin/phpunit -c phpunit.xml
        services:
          - mysql

definitions:
  services:
    mysql:
      image: mysql
      environment:
        MYSQL_DATABASE: 'homestead'
        MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
        MYSQL_USER: 'homestead'
        MYSQL_PASSWORD: 'secret'

Does anyone know what might be causing it?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DtjtF1
via IFTTT

Temporarily hide the Whoops page in Laravel 5.4?

When my PHP script goes wrong, I see a nice Whoops page with all details of the error.

However, sometimes I need to see the output of where it went wrong (for example in a loop with 1 million items, but only 1 of them gives a problem, I need to see which item). I flush the output after each item, so the page behind the Whoops page shows the last item at the bottom of the page.

Is there a way to hide the Whoops page (temporarily) ?

Using Chrome DevTools, I now hide the DIV that has the class 'Whoops_container' , but it would be nice if there's a more elegant way.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2EY3Mme
via IFTTT

How to convert a string that contains an associative array to an associative array type?

I have a string that contains associative array like that

$string = "['key1'=>'value1','key2'=>'value2','key3'=>'value3']";

and I want to convert it to an associative array so i can loop through it.

is there any way to do it ?

Thanks in advance .



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rqlKfm
via IFTTT