Ashraam

Ashraam

Member Since 3 Years Ago

Ajaccio

Web Developper at Ajaccio

Experience Points 71,070
Experience Level 15

3,930 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 651
Lessons
Completed
Best Reply Awards 6
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

21 Jun
3 weeks ago

Ashraam left a reply on Uncaught ReferenceError: Require Is Not Defined In Vuejs Laravel

Show us the content of your JS file

Ashraam left a reply on How To Get Data From Database?

Is there any reasons not to user Eloquent models ?

tips: the href in the a tag could be

{{ url($contact->username) }}

Ashraam left a reply on Progressive Web Apps

That would be nice !

Ashraam left a reply on WhereNotIn & Where Methods Not Working When Combined

Can you show us the query ? Or report that bug to github :p

Ashraam left a reply on Dynamic Model Names

You could do

$model = app(ucfirst($model_name));

$model->first();

Ashraam left a reply on Best Practice To Implement Code Revision

Why not use git the deploy your code en production and staging server ?

Ashraam left a reply on Making My Class Instance Persistent Over Next Request

Maybe you could store the model in a session or something ?

Ashraam left a reply on Should I Use An Accessor Or A Function?

I would user a function, maybe one day you'll have to pass some parameters to filter the result or something.

Ashraam left a reply on Login Over URL

You can pass the api token to the browser via a query string (well that's not safe but it should work), and then process it in you're controller like this

function logViaToken() {
    // Validate the request
    
    // Get the user
    $user = User::where('api_token', request('api_token'))->first();
    
    // Check if user exists
    
    // Log the user
    Auth::login($user);

    //r edirect
}

Ashraam left a reply on Authorization And Mysql Query

I already think to use a scope to filter the programmes the user can access. It limits the verification you're right. I've never used the global scope and it works really fine, thanks for the suggestion.

The only problem with the global scope (well it's not a big problem) is when i try to access a programme I shouldn't I receive an 404 not found error instead of a 403 unauthorized.

20 Jun
4 weeks ago

Ashraam left a reply on How To Select Some Entries From HasMany Relation?

Hi,

You could make a thing like this. I don't know the model names or relations names so I'll guess it

// fetch all the tracks from a specific job
$tracks = Job::find(X)->tracks;

$start = $tracks->first();
$end = $tracks->last();

// where Y is the index you want
$points = $tracks->slice(Y, 10);

Ashraam started a new conversation Authorization And Mysql Query

Hi everyone,

I'm not sure where to post this, I've got no problems but I'd wonder if I could optimize my code, so here is the thing.

I've got a model called 'Promotion' which is a sort of a container. To view a promotion a user must have the authorization according to his role and his company.

For the promotion owner this is just a simple verification like promotion->owner_id === user->id so no problem

My concern is for the real estate agents, they can view a promotion only if their company has been attached to the promotion via a 'Mandat'. So if I'm listing all the promotions on a page, for each row the gate will query the database like

select * from `mandats` where `mandats`.`promotion_id` = X and `mandats`.`promotion_id` is not null and `company_id` = Y limit 1

Is there a better way using the authorization when there are queries ? Is there any other solutions ?

Thanks

22 Apr
2 months ago

Ashraam left a reply on Cannot Upload Laravel Project To Git

the composer will recreate the vendor folder with all the packages that are used in your app

Ashraam left a reply on How To Allow Blade To Except (<a Href>, <br /> ... Etc)

{{ $code }} will strip tags {!! $code !!} won't

Ashraam left a reply on Cannot Upload Laravel Project To Git

the vendor folder (like node_modules, etc) are ignored in the .gitignore file that makes sense.

On your server run a composer install command

Ashraam left a reply on Non-object Error Only When Using Regular Function Call (not With Dd() )

Well if getProject() return null your code will fail.

Try

{{ optional($task->getProject())->id }}

Project and Task seems to be related, why don't you use laravel relationship ?

Ashraam left a reply on PHP

Can you be more explicit ? like you us your code...

A loop is a basic php feature maybe take a look at this

Ashraam left a reply on Laravel Migrate Error

Well the table already exist in the database (you probably had an error during the previous migration, it creates users table but did not finish the job)

So delete the table manually or try artisan migrate:refresh

Ashraam left a reply on Login Interface Take A Long Time To Display

do you load some external script on the login page ?

Do you use a custom login controller or laravel native ?

21 Apr
2 months ago

Ashraam left a reply on Getting "Trying To Get Property Of Non-object" In Blade View.

Did you try to dd($club) and dd($club->president)

Ashraam left a reply on Page Loads On My Machine But Return 500 Error Online

ssh to your server and in your app folder there should be a /storage/log with logs in it

Ashraam left a reply on Page Loads On My Machine But Return 500 Error Online

@successdav can you show us the log in /storage/log/

Ashraam left a reply on Trying To Get Property Of Non-object

@screwtape_mk Ok, nice you fixed it then :)

Ashraam left a reply on How To Apply Auth?

@aishahyaacob then mark the post as solved please :)

20 Apr
2 months ago

Ashraam left a reply on How To Apply Auth?

Did you apply the auth middleware ?

I think this can cause the bug too, so replace the all() to get()

public function score()
    {
        $user_id = Auth::user()->id;
        $totalMarks= QuestionAnswer::where('user_id',$user_id)->get();
        $timestamps = QuestionAnswer::all();

        return view('student.q_a.score', compact('totalMarks', 'timestamps'));
    }
19 Apr
2 months ago

Ashraam left a reply on Theme Assets To Compile With Mix

Usually I put the assets in the resources folder and copy them using laravel mix. (I put them in a specific folder IE template and then change the scripts/styles link in the code)

Not sure that's the best way, I hope we'll have some feedback too

Ashraam left a reply on CORS Using Laravel And Axios

You should take a look at this screencast

Ashraam left a reply on Foreign Key

@mouzak in your controller

example

$salarie = Salarie::findOrFail($id);

$salarie->relationPaie()->save(new Paie($attributes));

using the relationship will automatically feed salarie_id on the paies table

18 Apr
3 months ago

Ashraam left a reply on Vue Order Of Computing A Method Issue

I don't understand what you really want to achieve here ?

Do you have any errors ?

Axios is a promise based HTTP client, you have the catch method but what about the then method for a successful response ?

Ashraam left a reply on Laravel Blade And Javascript

Try to put the script code inside the body tag

Ashraam left a reply on Filtering Through Array For Specific Name

You can't use the filter method on the name attribute, it has to be used on the array itself (countrydata)

computed: {
            countryFilteredList() {
                return this.countrydata.filter((country) => {
            //your stuff
                });
            }
        },

Ashraam left a reply on Coupon Code Verification Upon Registration

Can you be more specific ?

What happens if the coupon is invalid or inexistant ?

Ashraam left a reply on Model::paginate() And Then ->append('attribute')

So you want to append some data to the result array ?

$users = User::paginate(15);

$custom = collect(['my_data' => 'My custom data here']);

$data = $custom->merge($users);

Ashraam left a reply on Foreign Key

you could do this (if I understood what you want)

$salarie->relationPaie()->save(new Paie($attributes));

Ashraam left a reply on Trying To Get Property Of Non-object

what happens if you do $bookingPayments->first()->toArray() ?

Ashraam left a reply on Foreign Key

Can you me more explicit ? Show us the models or the database structure maybe

Ashraam left a reply on Inserting The Information For A Range Of Dates

You could try the CarbonPeriod like this

$period = CarbonPeriod::create($request()->only('start_date', 'end_date'));

foreach($period as $date) {
    // Do your stuff
}

Ashraam left a reply on Trying To Get Property Of Non-object

What happens if you just do "$bookingPayments->first()"

You could also use the optional helper to prevent application crash

optional($bookingPayments->first())->employee_id

Ashraam left a reply on Incrementing A Count Field In Another Table

You're probably using a Many to Many relationship so in your Post model I would do this

public function addCategories($array)
    {
        $this->categories()->sync($array);

        $this->categories()->each(function($category) {
            $category->increment('count');
        });
    }
11 Mar
4 months ago

Ashraam started a new conversation Testing File Upload And Resizing Won't Work

Hi everyone,

I'm learning to develop using the TDD way and I'm facing this problem I can't solve.

I'm uploading an image which is resized and store in database.

When I'm doing it manually (using my browser like a regular user) it works, but the test fail.

Here is my controller:

public function store(Product $product)
    {
        //$name = request('image')->store('products', 'public');

        $name = str_random(50).'.jpg';
        $path = storage_path('app/public/products/'.$name);

        $image = Image::make(request('image'));
        $image->fit(400, 400);
        $image->save($path);

        $product->photos()->save(new Photo([
            'name' => $name
        ]));

        return redirect($product->adminPath());
    }

and here is my test

public function a_user_can_add_photos_to_the_product()
    {
        $this->withoutExceptionHandling();
        $this->signIn();

        $product = ProductFactory::create();

        Storage::fake('public');

        $this->post($product->adminPath('/photos'), [
            'image' => UploadedFile::fake()->image('photo.jpg')
        ])->assertRedirect($product->adminPath());

        $product->load(['photos']);

        tap($product->photos->first(), function ($photo) {
            $this->assertInstanceOf('App\Photo', $photo);

            Storage::disk('public')->assertExists($photo->name);
        });

        $this->assertEquals(1, $product->photos->count());
    }

At this point the test will fail, but If i comment the resize part and use the store method on the request like this:

Tests\Feature\ManageProductPhotoTest::a_user_can_add_photos_to_the_product
Unable to find a file at path [pJ1Zd19XT0aF9fc5W1famc3n7WwxBt3L9MDB0yRJNlVYcWkMwk.jpg].
Failed asserting that false is true.
public function store(Product $product)
    {
        $name = request('image')->store('products', 'public');

        /*$name = str_random(50).'.jpg';
        $path = storage_path('app/public/products/'.$name);

        $image = Image::make(request('image'));
        $image->fit(400, 400);
        $image->save($path);*/

        $product->photos()->save(new Photo([
            'name' => $name
        ]));

        return redirect($product->adminPath());
    }

The test passes.

How can I solve this issue ?

23 Nov
7 months ago

Ashraam left a reply on Problem In Route

A more explicit code sample would be nice :-)

Ashraam left a reply on Maximum Function Nesting Level Reached

What's the error ?

Did you try to dump the invoice model before saving it ?

22 Nov
7 months ago

Ashraam left a reply on Create Nova User On Custom User Table

Not sure about that but did you update the basic User resource (in app/nova) to reflect your database structure ?

Ashraam left a reply on Get Positions(Rank) For Pupils In Report App

sure @ayomaid08

First of all the basic on redis and sorted sets

#connection to redis
redis-cli

#Create and populate the sorted set (ZADD [set name] [value] [key])
ZADD setname 25 A

#You can populate the set with many key/value at the same time like this
ZADD setname 32 B 17 C 14 D 5 E

#If you want the rank of the key A in the descendant order
ZREVRANK setname A
(integer 1)

#In the ascendant order
ZRANK setname A
(integer 3)

#If you want the full ranking with the score
ZREVRANK setname 0 -1 WITHSCORES
1) "B"
 2) "32"
 3) "A"
 4) "25"
 5) "C"
 6) "17"
 7) "D"
 8) "14"
 9) "E"
10) "5"

Now with PHP and the redis library it's the same way.

First of all you have to require the library like this

composer require predis/predis

In your controller

use Predis\Client;

$redis = new Client;

#Adding value to the set
$redis->zadd($setname, $value, $key);

#Getting the rank of a key
$redis->zrevrank($setname, $key);

#If you want the 25 best students with the score
$redis->zrevrange($setname, 0, 25, 'WITHSCORES');
21 Nov
7 months ago

Ashraam left a reply on Get Positions(Rank) For Pupils In Report App

You could use redis sorted sets (https://redis.io/commands#sorted_set) to get rank (ZRANK or ZREVRANK)

Ashraam left a reply on Forgot Password Not Working

What is the laravel version ? @

Ashraam left a reply on Vue Route-Link Issues

Do you use the router-view component in your app ?

Ashraam left a reply on How To Clear The Cart Value After Checkout?

Have you tried this:

$request->session()->forget('key');

$request->session()->flush();