Ashraam

Ashraam

Member Since 3 Years Ago

Ajaccio

Web Developper at Ajaccio

Experience Points 69,500
Experience Level 14

500 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 642
Lessons
Completed
Best Reply Awards 5
Best Reply
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.

22 Apr
1 month 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
1 month 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
1 month 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
1 month 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
2 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
3 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
6 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
6 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
6 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();

Ashraam left a reply on Escape Hatch From Middleware

Hello,

Can you copy/paste your middleware code ?

Ashraam left a reply on Forgot Password Not Working

Do you use the Notifiable trait (Illuminate\Notifications\Notifiable) on your user model ?

18 Oct
8 months ago

Ashraam left a reply on Laravel Nova Action Fields

You should add the code so we could see where is the error

16 Aug
10 months ago

Ashraam left a reply on Vue Router And Reloading, How To Redirect To The Requested Page

Not really, found an ugly way with localStorage (each time I change page I keep the last URI requested then on the mounted method of my main component I check if this variable exists..)

There must be another way I guess, but for now it work.

12 Mar
1 year ago

Ashraam started a new conversation Laravel Scout Prevent Auto Sync

Hi everyone,

I'll will have to use Algolia for searching purpose and I will use Scout because it's awesome, but I can't find the option to pause the syncing.

I don't want to sync the model when it's saved but I'd rather want to push updated indexes every hour or something like that.

How can I achieve that ?

Thanks

19 Dec
1 year ago

Ashraam left a reply on Vue Router And Reloading, How To Redirect To The Requested Page

That's not the problem here, I'm already using storage for token.

My problem is when I reload while on page /reset (don't care if auth or not) I'll be redirected to /login (if not auth) or root (if auth). But I'd like to stay on /reset

Ashraam started a new conversation Vue Router And Reloading, How To Redirect To The Requested Page

Hi everyone,

I've got a problem and I can't solve it, maybe someone here could help me.

When I reload the page (F5) I'm always redirected to /login (except if I've got a token in the store then I'll stay on /)

I'd like to stay on pages that don't require auth after a reload. eg: I'm on /reset, I reload the page and stay on /reset (right now after a reload I'm always redirected to /login)

It's the same if I copy / paste uri in the browser, always redirected to /login

How can I achieve that ?

Do you need something else in my code ?

thanks

Here is my vue-router confirguration

import Vue from 'vue'
import VueRouter from 'vue-router'

import store from './store';

Vue.use(VueRouter);

import Calendar from './vue/Calendar.vue'
import Login from './vue/Login.vue'
import Register from './vue/Register.vue'
import LostPassword from './vue/LostPassword.vue'


const routes = [
    {
        path: '/',
        name: 'index',
        component: Calendar,
        meta: {
            requiresAuth: true
        }
    },
    {
        path: '/login',
        name: 'login',
        component: Login
    },
    {
        path: '/register',
        name: 'register',
        component: Register
    },
    {
        path: '/reset',
        name: 'reset',
        component: LostPassword
    }
];

const router = new VueRouter({
    mode: 'history',
    routes
});

 
router.beforeEach((to, from, next) => {
    if (to.matched.some(m => m.meta.requiresAuth) && store.state.token === null) {
        return next('/login');
    } else {
        return next();
    }
});

export default router;
24 Oct
1 year ago

Ashraam started a new conversation Algolia Search (Scout) With Multiples Fields

Hi everyone,

Let' say I want to create a phone book for a big company with multiples offices. My database is composed by 3 tables:

  • User
  • City (represent the office's location)
  • Role (a User can have multiple roles)

I'd like to create a form with 3 different fields to perform the query, how can I do that ?

For now I've got only 1 field and this is my main model User

    public function city()
    {
        return $this->belongsTo(City::class);
    }

    public function roles()
    {
        return $this->belongsToMany(Role::class);
    }

    public function toSearchableArray()
    {
        $office = $this->city;

        $array = [
            'name' => $this->name,
            'phone' => $this->phone,
            'postal_code' => $office->postal_code,
            'city' => $office->name,
        ];

        return $array;
    }

How would you do a research with Algolia and add filters to the query (City and Roles) ?

How should I store Roles ? Plain text ?

Thank you

14 May
2 years ago
11 May
2 years ago

Ashraam started a new conversation Vue-router, Transition On Dynamic Routes ?

Hi everyone,

I'm building a simple SPA and when I've got a transition on page change. But I've noticed a problem when I'm just updating the param in the url.

Example:

When I go from home -> users, there is my transition When I go from users -> user/1, there is the transition When I go from user/1 -> user/2, there is NO transition (at the beginning the component wasn't even updated.)

To update the component when I change the parameter in the url I have to watch for this param like

watch: {
        '$route' (to, from) {
            this.fetchHero(to.params.id);
        }
    }

Is there a when to apply my transition to this watcher ?

Thanks

10 May
2 years ago

Ashraam started a new conversation Filter Computed Data From Multiple Source

Hi everyone,

I'm learning VueJS and I've got a little problem.

I'm getting a list of users with vue-resource and I put then in the users variable.

I've a name field where I can filter them by name like this

filteredUsers() {
            let filteredUsers = this.users;

            if(this.filter.name.length > 1) {
                filteredUsers =  filteredUsers.filter(item => {
                    if(item.name.toLowerCase().includes(this.filter.name.toLowerCase())) {
                        return true;
                    }
                    return false;
                });
            }

Now I'd like to add one or more filter from select box like (account type, etc) I don't find a solution. I tried to add a if statement but it doesn't seems to work.

How would you do that ?

Thanks

11 Apr
2 years ago

Ashraam started a new conversation Reusable Functions (mixins ?)

Hi everyone,

I'm learning how to use VueJS (it's kinda awesome) and I'd like to know I could re-use some functions like this:

this.$http.get('/api/servers/'+this.id)
    .then(response => {
        return response.json();
    }, error => {
        swal({
            title: "Oops",
            type: 'error',
            text: `${error.status}: ${error.statusText}`
        });

        this.$router.push('/serveurs');
    })
    .then(data => {
        if(data) {
            this.server = data;
        }
    });

In this example I'm using Vue-Resource and Vue-Router and each time I'm using Vue-Resource to fetch some data I want to use this error function (now I'm writing this piece of code every time :/)

How should I do that ?

Thank you

08 Mar
2 years ago

Ashraam started a new conversation Problem With Http And Https

I everyone,

I'm working on my app on vagrant and it's working nicely, I push it on prod (with HTTPS url) and all my emails url doesn't work anymore.

Example

let's say my APP_URL in the .env is https://www.domain.com

all my links and assets in the mail are

url('test')
asset('images/test.png')

I grad the mails with mailtrap right now.

If I look to the source: the url is converted to http://www.domain.com/test the asset is converted to http://www.domain.com/images/test.png

If I copy paste the url or assets in my browser it doesn't work because https redirect like this url: http://www.domain.comtest asset: http://www.domain.comimages/test.png

It removes the first slash after the domain name...

How can I solve this problem ?

Thank you !