lundi 1 octobre 2018

How to retrieve the media of a related model with Laravel Medialibrary?

I have an Album model and Track model. They have OneToMany relationship. An Album can have many tracks and a track can only belong to one Album. I'm using media library to associate the files of a song which is the cover and the mp3 to a Track model.

In my AlbumController, I have a query like this;

$album = $album->where('id', $id)->with('tracks', 'artist')->first();
return view('admins.albums.show', compact('album'));

This loads the tracks of the album but not the media. In my views, I can get the media by looping through the tracks and calling the getMedia() function but what about for Api?

How can I return the media as a Json before it is sent as a response?



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

Water Mark on Image - intervention/image/src/Intervention/Image/Commands/Argument.php on line 41

How to solve this error, I'm trying to add watermark on the image but getting below errors:

libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: cHRM chunk does not match sRGB [Mon Oct 1 15:06:36 2018] PHP Fatal error: Maximum execution time of 60 seconds exceeded in /var/www/newProject/vendor/intervention/image/src/Intervention/Image/Commands/Argument.php on line 41



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

post route in Laravel

I have done everything the right way but my submit button doesnt do anything and I dont know why....

Here is my view

<form action="" method="POST" enctype="multipart/form-data">
     @csrf
    add users via excell<input name="file" class="form-control" style="padding-bottom:3em; margin-bottom:3em" type="file">
    <div style="display:inline;">

     <input type="submit" class="btn btn-primary btn-lg" value="ارفع" >
</div>
</form>

Here is my controller

function importUser(Request $request)
 {

 #code...
 }

and my route

Route::POST('ImportUsersFile', 'ExcelUserController@importUser')->name('importUser')->middleware('Admin');

Apparently, the flow dont get in the function import user. I tried to dd into it but nothing happend!



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

Do While Loop not triggered in cron job (Laravel)

The requirement is to set up a cron job that runs every 4 seconds. Since cron jobs can be executed only in minutes, I decided the trigger my job every minute and within the job, run it several time. Here's the code.

public function handle()
{

    $dt = Carbon::now();
    $counter = 60/4; //run the job every 4 seconds
    do {
        //logic goes here
        time_sleep_until($dt->addSeconds(4)->timestamp);
    } while ($counter-- > 0);
}

Cron job is scheduled as in crontab -e

*/1 * * * * /usr/bin/php /var/www/html/dashboard/artisan cronjob:pulldata

Job runs perfectly every 4 seconds when I execute it manually with the php artisan command. But, it executes only once a minute when it is triggered by the cronjob from crontab -e.



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

Modal work but it won't display properly when calling form another Vuejs component

I have a modal in a child vue component called from a parent component, when triggering and calling it the page get effected and get "modal-open" added to the body, but the modal it self doesn't showenter code here



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

Migration Process in Laravel

C:\xampp\htdocs\blog>php artisan migrate

Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table password_resets add index password_resets_email_index(email))



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

Laravel model event won't fire after ajax call

I'm using ajax to update my model User, the ajax part works fine since the data is updated successfully in the database, inside my controller action the update performed by :

$user->update($data);

The part that doesn't work:

I've used boots method updated inside my model like :

class User extends BaseModel
{
    ...

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

        static::updated(function($model){
            Log::info("updated");
            dd($model);
        });
    }
}

The event was never reached I'm not sure why.

Problem: I'm trying to perform an action after the model update but the event doesn't fire.



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