vendredi 1 avril 2016

After move lavarel 5.1 application for digital ocean i get the error ! 'App\Exceptions\Mail' not found

Hi,

After i change my application of hosting i get this error , can anyone help please ?

2016/04/01 09:29:23 [error] 9176#0: *5 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Class 'App\Exceptions\Mail' not found in /var/www/myproject/app/Exceptions/Handler_.php on line 37
PHP message: PHP Fatal error:  Class 'App\Exceptions\Mail' not found in /var/www/myapp/app/Exceptions/Handler_.php on line 37" while reading response header from upstream, client: 94.61.41.56, server: myproject.pt, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "rhcode.codeline.pt"



via Chebli Mohamed

Laravel 5.1 - How to get updates to relationships in static::updating event

I'm trying to create a trait (for models) that would automatically write all changes made to the model in 'adjustments' table. It would save changes in before and after jsons.

This is the code so far (from Laracasts):

trait LoggingTrait
{
    public static function boot()
    {
        parent::boot();

        static::updating(function($action){
            $action->adjustments()->create(
            [
                'user_id' => Auth::id(),
                'before' => json_encode(array_intersect_key($action->getOriginal(), $action->getDirty())),
                'after' => json_encode($action->getDirty())
            ]);
        });
    }

    public function adjustments()
    {
        return $this->morphMany(Adjustment::class, 'adjustable');
    }
}

This is working very well, except it doesn't save changes to related models.

To make it more clear, this is my Action model:

class Action extends Model
{
    use LoggingTrait;

    public function actionTypes()
    {
        return $this->belongsToMany(ActionType::class);
    }

    public function users()
    {
        return $this->belongsToMany(User::class);
    }

    public function spreadingMaterial()
    {
        return $this->belongsTo(SpreadingMaterial::class);
    }
}

The trait logs all the changes made to the actual Action model, but doesn't care for the changes made to the $action->users(), $action->spreadingMaterials() and $action->actionTypes(). How would I get these changes within the static::updating(...) event?

Or if that is not possible, any other idea on how to tackle this problem is more than welcome.



via Chebli Mohamed

Groupby query is not worked in laravel query builder

I am using below query ,

$data = DB::table('developers')
->select('iDeveloperId', 'vFirstName', 'vLastName', 'iGroupId')
->groupBy('vFirstName')
->get();

But i am getting an error like

Warning: Creating default object from empty value in /var/www/html/laravel_demo/query_builder/db_config.php on line 40

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hbmp_hims.developers.iDeveloperId' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by' in /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php:333 Stack trace: #0 /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php(333): PDO->prepare('select `iDevelo...') #1 /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php(662): Illuminate\Database\Connection->Illuminate\Database\{closure}(Object(Illuminate\Database\MySqlConnection), 'select `iDevelo...', Array) #2 /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php(629): Illuminate\Database\Connection->runQueryCallback('select `iDevelo...', Array, O in /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php on line 669

what the mistake i have done.

Note : it works when 'iDeveloperId' is used in the place of 'vFirstName'

Thanks in advance.....



via Chebli Mohamed

Larevl5.1 Join Query for 4 Tables

I need to join four tables in Join using Laravel and i need to get count of the values from 2 tables along with the other two table datas.

Table Name: users / timesplayed / user_avatar / privatemessages

I need to get all values from users and user_avatar table and Count of rows from the other Two Tables.

I have used the following join Query but i am getting count Error on joining the privatemessages table.

Can u rectify what is wrong in this Join Query.

$user_id = Auth::user()->users_id;
return $user_information = DB::table('users')
                        ->join('timesplayed','users.users_id','=','timesplayed.users_id')
                        ->join('user_avatar','user_avatar.user_avatar_id','=','users.avatar')
                        ->join('privatemessages','privatemessages.to_user_id','=','users.users_id')
                        ->select('users.*',DB::raw('COUNT(timesplayed.users_id) as total'),'user_avatar.user_avatar_id',DB::raw('COUNT(privatemessage.privatemessage_id)'))
                        ->where('privatemessages.status','=',1)
                        ->where('users.users_id','=',$user_id)
                        ->get();



via Chebli Mohamed

Laravel 5.1 deleting duplicates in DB with eloquent

I am wondering how to delete duplicate entries in the DB table, and keeping the new copies in the table. This is how my table looks like:

 $table->increments('id');
 $table->string('text');
 $table->string('type');
 $table->integer('external_id');
 $table->timestamps();

Since I am importing from other DB, and I would like to import all data once a day, means there will be some existing entries already in DB, and new entries as well. Since I need to keep only the entries that are new, I need to delete all old entries (duplicates and unique entries that are not new). Is there a way to do it with Eloquent in Laravel 5.1?



via Chebli Mohamed

Laravel 5 Ban users via Bican roles

I'm making a application in laravel 5.1 and I'm using Bican roles to manage the user's permissions and role names. Now I want to be able to ban my users.

So if I ban a user, the application needs to check globally the application if the user is banned. Im storing the bans in a new table outside of the users table because in that way, I can always find all the bans there were given to a specific user.

My database structure looks like this:

+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+------------------+------------+----------------+---------------------------------+----------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE | CHARACTER_MAXIMUM_LENGTH | CHARACTER_OCTET_LENGTH | NUMERIC_PRECISION | NUMERIC_SCALE | CHARACTER_SET_NAME | COLLATION_NAME     | COLUMN_TYPE      | COLUMN_KEY | EXTRA          | PRIVILEGES                      | COLUMN_COMMENT |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+------------------+------------+----------------+---------------------------------+----------------+
| def           | xenionode    | banned     | id          |                1 | NULL           | NO          | int       | NULL                     | NULL                   |                10 |             0 | NULL               | NULL               | int(11) unsigned | PRI        | auto_increment | select,insert,update,references |                |
| def           | xenionode    | banned     | user_id     |                2 | NULL           | NO          | int       | NULL                     | NULL                   |                10 |             0 | NULL               | NULL               | int(11) unsigned | MUL        |                | select,insert,update,references |                |
| def           | xenionode    | banned     | banned_by   |                3 | NULL           | NO          | int       | NULL                     | NULL                   |                10 |             0 | NULL               | NULL               | int(11) unsigned | MUL        |                | select,insert,update,references |                |
| def           | xenionode    | banned     | reason      |                4 | NULL           | NO          | varchar   |                      255 |                   1020 | NULL              | NULL          | utf8mb4            | utf8mb4_unicode_ci | varchar(255)     |            |                | select,insert,update,references |                |
| def           | xenionode    | banned     | expires     |                5 | NULL           | NO          | datetime  | NULL                     | NULL                   | NULL              | NULL          | NULL               | NULL               | datetime         |            |                | select,insert,update,references |                |
| def           | xenionode    | banned     | lifted      |                6 | NULL           | YES         | datetime  | NULL                     | NULL                   | NULL              | NULL          | NULL               | NULL               | datetime         |            |                | select,insert,update,references |                |
| def           | xenionode    | banned     | lifted_by   |                7 | NULL           | YES         | int       | NULL                     | NULL                   |                10 |             0 | NULL               | NULL               | int(11) unsigned | MUL        |                | select,insert,update,references |                |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+------------------+------------+----------------+---------------------------------+----------------+
7 rows in set

Now I want if a user is banned, the user still can login, but redirects always to a view called banned.

I really don't knwo how I can do this global check in Laravel 5 in a propper way, if someone could help me out, that would be awesome!

Kindest regards

Robin



via Chebli Mohamed

Laravel redirect route and response json

How can I return a redirect routes with inputs etc. with a json response using laravel 5.1.

My current return looks like this:

return redirect()->route('root')->with('message', 'Success')->withInput();

and here is a sample json response from the docs:

return response()->json(['name' => 'Abigail', 'state' => 'CA']);

But I do not know how to put them together so to say.



via Chebli Mohamed