Mehdi_Souihed

Mehdi_Souihed

Member Since 3 Years Ago

Experience Points 2,675
Experience
Level
Lessons Completed 58
Lessons
Completed
Best Reply Awards 2
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

14 Oct
3 years ago

Mehdi_Souihed left a reply on File Upload Unkown Error With Phpunit

Hi Guys,

I came across a similar problem while trying to test uploading a file on a form. Here is what I have done to make it work :

    
    // ... Your test file ...

    // array
        $file = 'public/uploads/file.pdf';
        $this->assertFileExists($file);
        $pdf = new UploadedFile ($file, null, 'application/pdf', null, null, true);
        $form = $this->fakeFormData();
        $form['file'] = $file;
        $this->visit('signup')->submitForm('Submit', $form);

However if you typically have the following rule in your validator:

   //...
     'file' => 'mimes:pdf',
  //...

You will get an error in these terms : ** file must be of one these types: pdf**

This is because the above rule checks against the mimeType sent by the browser (which is not a terribly good practice) and the PHPUnit crawler always sends a mime type of 'application/octet-stream' and then laravel winges.

So to make the server check itself the mimeType and not rely on the browser, we have to define a custom validator rule:


          Validator::extend('is_pdf', function($attribute, $value, $parameters, $validator) {

            $mime = \Request::file($attribute)->getMimeType();
                        return $mime == 'application/pdf';
        });

You should also define a custom error message, it is explained in the Laravel Doc (link above).

02 Apr
3 years ago

Mehdi_Souihed left a reply on Eloquent Eager Loading Modify 'Where ... IN ' Clause

@constb For records this is what my query looks like now. It kind of simulates eager loading with the ability to choose which records go in the WHERE .. IN(...) clause automatically generated by Eloquent

$users = User::whereHas('settings', function ($q) { 
             $q->where('settingsid', 16)->where('value', 'LIKE', '%o%'); 
         
         })->with(['settings' => function ($q) {
              $q->whereIn('settingsid', $this->settingsColumns);
        // Get only some columns in the settings table
              $q->addSelect(['value', 'id', 'userid', 'settingsid']); 
  
         }])->get();

Thanks

Mehdi_Souihed left a reply on Eloquent Eager Loading Modify 'Where ... IN ' Clause

Thanks very much @constb

I have tinkered with it a bit and it looks like it is going to solve it :-)

I'll update this thread very soon and let you know

Cheers

Mehdi_Souihed left a reply on Eloquent Eager Loading Modify 'Where ... IN ' Clause

@constb Thanks for your reply

I have tried that approach, the result of that query would be :

User, Location, Dept.
5   , London

Billing is left out and not returned.

Mehdi_Souihed left a reply on Eloquent Eager Loading Modify 'Where ... IN ' Clause

Thanks for your replies.

Right, I have a user_settings table which is an Entity Attribute Value Model, I know ... that's not great. It basically looks like this :

settingsid, userid, value 15 , 5, Billing 15 , 6, Operations 16 , 5, London 16 , 6, Edinburgh ...

What I already have is all settings for each user lined up in rows : User, Location, Dept. 5 , London, Billing 6 , Edinburgh, Operations

I am looking to be able to filter per Location or Dept or any other setting.

I hope that is clear enough, thank you

Mehdi_Souihed started a new conversation Eloquent Eager Loading Modify 'Where ... IN ' Clause

Hi,

I am using eager loading with one model and the query looks like this

select `value`, `id`, `userid`, `settingsid` from `user_settings` where `user_settings`.`userid` in ('1', '4', '5', '8', '9', '11', '13', '14', '15', '16', '28')

I have a User model and a User settings models containing a foreign key to User.

What I would like to do is have control over the User ids used by the eager loading.

Is that possible

23 Mar
3 years ago

Mehdi_Souihed started a new conversation Codeception Dump Page

Hi all,

Does anyone know how to dump the html page Codeception uses for the tests ?

I would like to be able to see what Codeception sees because I have a failing test that doesn't make sense to me.

Thank you

03 Mar
3 years ago

Mehdi_Souihed left a reply on Class Not Found Exception

@User62 Have included the class Class 'CreateTablePlayer' in your migration ?

23 Feb
3 years ago

Mehdi_Souihed left a reply on [L5] Role And Permission

@nazar1987 You need to create the 'models' folder yourself and then put the different files in it (Role.php, Permission.php)

Also don't forget to update the entrust config file config/entrust.php with the correct namespaces for Role and Permission models because they are defaulted to the [base namespace]:(https://github.com/Zizaco/entrust/blob/7037d6ab52f9341c26e61fc61ca90813cdb9b32c/src/config/config.php#L14).

18 Feb
3 years ago

Mehdi_Souihed left a reply on Eloquent. Infinite Children Into Usable Array And Render It To Nested Ul

@AlnourAltegani @pmall I see, this is at the database level ;-) I came across that problem for a hierarchy of users. I have used Baum to manage the hierarchies for me. For your case I guess you'll need to keep querying the database recursively.

Mehdi_Souihed left a reply on Eloquent. Infinite Children Into Usable Array And Render It To Nested Ul

@pmall From his question @AlnourAltegani is only looking for the values of his elements :

I have just tested the following code (I have normalised a bit the array which contained)

$categories = array(
        'name' => 'cat1',
        'children' => array (
                
                'name' => 'cat1',
                'children' => array (
                    
                     'name'=>'subcat1',
                     'children'=> array ()
                )
            )
);


function test_print($item, $key)
{
    echo "Category name : $item\n";
}

array_walk_recursive($categories, 'test_print');

Which outputed :

Category name : cat1
Category name : cat1
Category name : subcat1

Mehdi_Souihed left a reply on Eloquent. Infinite Children Into Usable Array And Render It To Nested Ul

The most straightforward however maybe not fastest way is to use a array_walk_recursive function to traverse your array (which is called a tree datastructure) Here is the snippet from the PHP doc adapted to your case :


function test_print($item, $key)
{
    echo "Category name : $item\n";
}

array_walk_recursive($categories, 'test_print');

Another method would be to use the Recursive Iterator however I think in your case it is overkill.

Then to print it to an unordered list you have a Laravel HTML helper, if you use Laravel 5 you will need to install illuminate

Pass your array to your view and print it with :

  {{ HTML::ul($categories) }}
17 Feb
3 years ago

Mehdi_Souihed left a reply on Redirect In AfterFilter

@dante_dd you need to return the result as follows :

if ($something) {
           return $this->afterFilter(function($route, $request, $response)
            {
                return Redirect::to('http://google.com', 301);
            });
        }

Note the return on line 2.

Mehdi_Souihed left a reply on Laravel 4 TokenMismatchException Error When Login Or Signup

Are you sure that

Input::get('_token')

is not empty ?

If it is not I would suggest clearing all your caches.

Mehdi_Souihed left a reply on Access Errors In Form Macro

You can probably access your $errors variable using :

Session::get('errors');

Mehdi_Souihed left a reply on Eloquent DB Questions....

If what you mean is how to resolve your foreign key and get joined data from your three tables, you could do the following :

VendorDetails::with('vendor')->with('client')->where('client_id', =, Session::get('client_id')) ;