jeudi 29 juin 2023

How to get sorted one to many field with respect to max of a column in Laravel?

I am using Laravel 5.1 and want to get items sorted with respect to one column of the many field.

I have members and subscriptions. Each member has multiple subscriptions with end date as one of the column. I want to sort members with respect to subscriptions with maximum end dates.

I am using the code below but it selects first subscriptions and sort members with respect to first subscriptions.

Member::join('trn_subscriptions as subs', 'subs.member_id', '=', 'mst_members.id')
            ->select('mst_members.*', DB::raw('max(subs.end_date) latest_sub'))
            ->groupBy('mst_members.id')
            ->orderBy('latest_sub','desc')
            ->where('subs.end_date', '<', Carbon::today());

How can I achive sorting with respect to subscriptions for each member having maximum end dates below certain date?

Thank you in advance.



via Chebli Mohamed

mardi 27 juin 2023

How to Count Data from Another Function

I have a trouble from my controller. When i want to count the array from another function in controller is get a error cannot to count

I get this error

Call to a member function get() on array

This my controller :

Function A
public function detailFees(){
$dataArray = array(
    'datapayment' => $datapayment,
    'countafter' => $countafter,
    'countbefore' => $countbefore
  );
}

Function B
public function data(){
$data = count($this->detailFees($market)->get(datapayment))
}

I want to count data with result in number

Thanks for help!



via Chebli Mohamed

lundi 26 juin 2023

Enable tls for phpredis configuration in laravel 5.6 application

the error shows that something like

[2023-06-27 13:51:56] dev.ERROR: read error on connection to {"exception":"[object] (RedisException(code: 0): read error on connection to /var/www/adflow2/webapp/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:69)

am currently using this configuration in config/database.php file. but it doesn't enable tls in aws.

    'redis' => [
        'client' => 'phpredis',

        'default' => [
            'scheme' => 'tls',
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_DB', 0),
         
        ],
        'session' => [
            'scheme' => 'tls',
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_SESSION_DB', 1), // Use a different Redis database for session
         
        ],
    ],

also restart the server after making changes.



via Chebli Mohamed

mercredi 21 juin 2023

How can I fetch business detail by business ID in Laravel?

how am i going to fetch business detail by business ID in Laravel. how to retrieve the information about a business, such as its name, description, and address, given the business ID,s List.

Business Id 123 124 125

If i click on 123 I should get the information regarding 123. Business list is being fetched using user_email(unique and foreign key).

NOte- One user can have multiple businesses.



via Chebli Mohamed

How To Downgrade Laravel 10 To Laravel 8 Version?

How To Downgrade Laravel 10 To Laravel 8 Version ?? if you know please reply ..How To Downgrade The body of your question contains your problem details and results. Minimum 220 characters. your title still describes the problem! Now is a good time to make sure that Thankyou



via Chebli Mohamed

mardi 20 juin 2023

Property ... does not exist on this collection instance [duplicate]

I have 3 table :

  • Table Grade :

    // MIGRATION
    Schema::create('grade', function (Blueprint $table) {
                $table->id();
                $table->string('grade');
                $table->timestamps();
            });
    
    // MODEL
    public function relationToBobot(){
    return $this->belongsToMany(Bobot::class, 'gradebobot', 'grade_id', 'bobot_id');
    }
    
  • Table Bobot :

    // MIGRATION
    Schema::create('bobot', function (Blueprint $table) {
                $table->id();
                $table->string('bobot');
                $table->integer('harga');
                $table->timestamps();
            });
    
    // MODEL
    public function relationToGrade(){
    return $this->belongsToMany(Grade::class, 'gradebobot', 'bobot_id', 'grade_id');
    }
    
  • Table Grade Bobot (Pivot)

    // MIGRATION
    Schema::create('gradebobot', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('grade_id')->unsigned();
                $table->bigInteger('bobot_id')->unsigned();
                $table->timestamps();
                $table->foreign('grade_id')->references('id')->on('grade')->onDelete('cascade');
                $table->foreign('bobot_id')->references('id')->on('bobot')->onDelete('cascade');
            });
    

I want to show "grade" where have "bobot". This is my Controller :

public function test(){
        $grade = Grade::all();
    return view('welcome', compact('grade'));
    }

And this is my Blade View :

@foreach ($grade as $item)
    <h1></h1>
    @foreach ($grade->relationToBobot->where('grade_id', $item->id) as $item)
        <p></p>
    @endforeach
@endforeach

Can someone help me.. Thanks

Expectation :

A

100

200

300

400

B

500

600

700

800

C

900

1000

1100

1200



via Chebli Mohamed

lundi 19 juin 2023

file_exists(): open_basedir restriction in effect

I am develope a laravel app. I go to the route folder myapp/routes/web.php on serve and register a new route as follows:

Route::get('/linkstorage', function () {
    Artisan::call('storage:link');
});

when i enter https://chanvay.store/linkstorage and hit enter. Error appeared

ErrorException (E_WARNING) file_exists(): open_basedir restriction in effect. File(/home/chanvays/domains/chanvay.store/public_html/public/storage) is not within the allowed path(s): (/home/chanvays/:/tmp:/var/tmp:/opt/alt/php81/usr/share/pear/:/dev/urandom:/usr/local/lib/php/:/usr/local/php81/lib/php/) Anybody help me ?

Anybody help me fix this issue ? I can not comman php artisan storage:link on serve.



via Chebli Mohamed