mercredi 2 décembre 2020

How get old value of select in laravel 8 blade?

I want to get the old selected value of Select after submit the form with the same Select. I tried doing this code below but it doesn't work old helper every time back me to the first item of Select, please any suggestion to fix this?

<form action="/plaintes/trib" method="POST">
        @csrf
        <label for="choose_trib"> choose : </label>
        <select name="choose_trib" id="choose_trib" onchange="this.form.submit()">
            <option value="-1" > choose your trib</option>
            @foreach ($tribs as $trib)
                <option  value="" >  </option>     
            @endforeach 
        </select>
</form>


via Chebli Mohamed

Laravel order by child in the same table

I have a thread table with replies in the same table named posts:

       ID  |  PARENT_ID  | CATEGORY_ID |  CREATED_AT  | UPDATED_AT

If the "PARENT_ID" not null then is a thread otherwise is a reply.

With a "CATEGORY_ID=3" i want to get all threads with pagination ordered by "UPDATED_AT" of last reply if there is one.



via Chebli Mohamed

mardi 1 décembre 2020

Laravel slow mysql query latency

echo "\nexec first time:";
$currentTime = microtime(true);
$users->paginate($request->length, ['*'], 'page', $request->start/$request->length + 1);
echo microtime(true) - $currentTime;

echo "\nexec second time:";
$currentTime = microtime(true);
$users->paginate($request->length, ['*'], 'page', $request->start/$request->length + 1);
echo microtime(true) - $currentTime;

The above is the code in my controller for testing the latency when query the mysql. As you can see I execute the same command twice. The execute latency is different.

exec first time: 2.7011959552765
exec second time: 0.78873896598816

The above is the output of the performance. During the Laravel document, the server provider contains the DI pattern to share the DB connection. If we are not recreate the connection then what happened is this result? If the result is belongs to recreation, then how can I share the connection pool?



via Chebli Mohamed

WhereHas is not working in laravel server

WhereHas condition is not working in the server because of the updated version. but it is working in local. so plesase suggest me the alternative of this: here is the query i am trying to execute:

$purchased_courses = Course::with(['students' => function($query) {
                $query->where('id', Auth::id());
            }])
            ->with('lessons')
            ->orderBy('id', 'desc')
            ->get();


via Chebli Mohamed

how to use or import ffmpeg in a laravel controller

i have already installed the laravel-ffmpeg via composer in my project

composer require pbmedia/laravel-ffmpeg

then i added class to config/app.php file as documentation says

// config/app.php

'providers' => [
    ...
    ProtoneMedia\LaravelFFMpeg\Support\ServiceProvider::class,
    ...
];

'aliases' => [
    ...
    'FFMpeg' => ProtoneMedia\LaravelFFMpeg\Support\FFMpeg::class
    ...
];

then publish this config file

php artisan vendor:publish --provider="ProtoneMedia\LaravelFFMpeg\Support\ServiceProvider"

now my question is to use this package in my project, how should i use this into my controller i saw many post and ques regarding this and i get these

use FFMpeg;
use FFMpeg\FFMpeg;
use Pbmedia\LaravelFFMpeg\FFMpeg;
use ProtoneMedia\LaravelFFMpeg\FFMpeg;
.
.
.

which one is correct, my goal is to trim a video, but which one works for that i am so confused

//config/laravel-ffmpeg.php

<?php

return [
    'ffmpeg' => [
        'binaries' => env('FFMPEG_BINARIES', 'ffmpeg'),
        'threads'  => 12,
    ],

    'ffprobe' => [
        'binaries' => env('FFPROBE_BINARIES', 'ffprobe'),
    ],

    'timeout' => 3600,

    'enable_logging' => true,

    'set_command_and_error_output_on_exception' => false,
];

please help me out, thanks in advance



via Chebli Mohamed

Getting unserialize(): Error at offset 65522 of 65535 bytes when trying to use Gate::denies('view_home_dashboard')

I'm using Laravel Framework 5.6.40 and I'm trying to integrate Spatie's Laravel Permissiosn Package. Everything works except whenever I try to use

Gate::denies('view_home_dashboard') 

I'm getting an exception.

enter image description here

I've tried a number of solutions:

  • Clearing the cache
  • Generating a new Key (artisan key generate)
  • Clearing the Config
  • Changing to protected static $serialize = false; and protected static $serialize = true;

But nothing works. I'm stuck with this error for the last 5 hours. Hopefully someone can help me out.



via Chebli Mohamed

Cannot show data php debug bar in laravel 5.4

Debug is set to true, why can I not see the laravel debug bar?

APP_DEBUG=true APP_LOG_LEVEL=debug

image here



via Chebli Mohamed