lundi 21 septembre 2020

1 Salut, j'essaye de télécharger une image avec Laravel 5

I can't upload a file in laravel, it gives me the Method Illuminate \ Validation \ Validator :: validateAvatar does not exist error. so say that everything is well done

I created a validator function which return the validates



via Chebli Mohamed

Laravel 5.4 - Get logged user info with other table (contests) information

Showing right now

Right now it's showing current logged in user information.

Current logged user information.

current logged user information.

But I want to show current user information with other contestars information.

Here it's showing two results but I want to show all of them

here it's showing two results but I want to show all of them

Contest Model

contests model

Any help will be appreciated. Thanks.



via Chebli Mohamed

Laravel strange behavior in 1 to Many relationship

Very strange situation in Laravel 1 to Many relationships, My User model

public function reminder(){

        return $this->hasMany(Reminder::class);
    }

Reminder Model

public function user(){

        return $this->belongsTo(User::class);
    }

When I try to get

dd(auth()->user()->reminder) -> null
$user_id = auth()->user()->id;
$user = User::findOrFail($user_id);
dd($user->reminder) -> success I got results.

Question is why I can't get relationship result using auth()->user()->reminder???



via Chebli Mohamed

dimanche 20 septembre 2020

Laravel: Getting Orders between a certain time

I am bit a new to Laravel. I am trying to get a orders between a certain point in time. I have a variable $streamStartTime that is set early on to Carbon::now()->timestamp.

$streamStartTime = Carbon::now()->timestamp;

Later on, I call this:

 $streamPaidOrders = Order::->whereBetween('orders.created_at', [$streamStartTime, Carbon::now()]);

Would those 2 parameters give me orders between them or are they in different formats?



via Chebli Mohamed

Using Validator methods on custom validation rules in AppServiceProvider

This is what my AppServiceProvider's boot method looks like. My custom rule must do this: it must check that the input specified in 0'th parameter does exist and is not null, then must check current attribute's value is and array and is not null;

The problem is, when I try to access $validator's getValue() or validateRequired() methods app gives me an exception like:

Method [getValue] does not exist.

How can I access those methods?

      Validator::extendImplicit('imageArrayWith', function($attribute, $value, $parameters, $validator){
        $imageArray = json_decode($value);
        $requiredRow = $parameters[0];
        $requiredRowVal = $validator->getValue($requiredRow);
        if($validator->validateRequired($requiredWithRow)){
          if(is_array($imageArray)){
            if(count($imageArray) == 0){
              return false;
            }
          }
          return true;
        }else{
          return false;
        }
      });


via Chebli Mohamed

Laravel return 404 for js file that it exist

I have newly added app.js file which I include in the footer as follow:

<script src="" defer></script>

it return 404 status code, but the file exists and the generated URI is correct, what is the problem?

it work fine locally, but on production server it return 404



via Chebli Mohamed

samedi 19 septembre 2020

saving dropdown list value in laravel

I need assistance please. The scenario: I have a table called users and transactions in laravel. Created a blade for transaction table which will pull data as user id drop down list from users table. All user id of users table are show in transaction with dropdown lists. Transaction table has amount column with debit/credit options. User table has total amount column.

My controller -

DB::table('users')->where('userid', $request->userid)->increment('amount', $request->amount); and DB::table('users')->where('userid', $request->userid)->decrement('amount', $request->amount);

What I want to achieve

Currently, the dropdown list is working and save data in transaction table but amount can’t be debited or credited in total amount in user tables.

$request->userid is not getting value from dropdown list.

Please how do I achieve this? Thank you.



via Chebli Mohamed