Ashraam

Ashraam

Web Developper at Ajaccio

Member Since 3 Years Ago

Ajaccio

Experience Points
77,860
Total
Experience

2,140 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
684
Lessons
Completed
Best Reply Awards
11
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.

Level 16
77,860 XP
Dec
04
1 week ago
Activity icon

Started a new Conversation Deploy On Multiple Server: Question About .env File

Hi, I just started to use a envoyer account and I've got this little problem I don't know how to handle.

I will deploy my site on multiple server (a load balancer will redirect the requests), when I deploy my code via Envoyer it syncs the .env file to the servers (using the manage environment button on envoyer), it's nice because almost all the keys should be the same on every server.

But how can I do if I want a specific value per server e.g: APP_SERVER=XXXX should be different between server 1 and 2.

Is there a solution ?

Thanks

Activity icon

Awarded Best Reply on Load Balancer And CSRF Token Exception

Well, I found out after hour for almost nothing, my APP_NAME was different on Server 1 and Server 2, so there was two different sessions.... :/

I found out while watch the headers in the inspect console !

Activity icon

Replied to Load Balancer And CSRF Token Exception

Well, I found out after hour for almost nothing, my APP_NAME was different on Server 1 and Server 2, so there was two different sessions.... :/

I found out while watch the headers in the inspect console !

Dec
03
1 week ago
Activity icon

Started a new Conversation Load Balancer And CSRF Token Exception

I am testing an infrastructure for a web application which include a load balancer, a database server and 2 web servers. All the server are on the same datacenter (provided by Digital Ocean) The redis server is a managed database product from DO too.

I'm using laravel 6.6.

The load balancer works well (using the Round Robin algorithm), but when I try to login, I always got 419 page exception.

Here is the detail of my env file

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=sync
SESSION_DRIVER=redis
SESSION_LIFETIME=120

I am using redis to share the session, but it's not working. I can read and write to the redis cluster.

When I go on a specific web server I can login without any problem.

Someone has an idea to solve this issue ? Tell me if you want more informations

Thanks

Oct
16
1 month ago
Activity icon

Started a new Conversation Updating Router

Hi,

I've built a resource-tool and I wonder how I can change the url after a specific method.

For now I'm using the window.location.href, it's working but it's also reloading (I'm losing some toast notification for example).

How can I reload the router in Nova ?

Thanks

Sep
27
2 months ago
Activity icon

Replied to Laravel Nova Action Fields

You can do something like

Text::make('Field name', function() {
    return $this->a.'/'.$this->b;
})->onlyOnDetail()
Activity icon

Replied to Display Memory Usage / Time In Artisan Command

for the time you can use the microtime function.

$start = microtime(true);
// your code
$execution_time = microtime(true) - $start;
Activity icon

Replied to Many To Many Relationship Attach User When Creating A Project

@stephanha54 hey I think I know why it didn't work, you can attach / sync pivot data on a single model. In my code was doing it on the whole collection of projects.

Maybe this would work better

$user->projects()->find(X)->attach([data]);
Activity icon

Replied to Question About The Connection For A User

I don't understand why you are trying to achieve here. Is there any errors ?

Activity icon

Replied to Eloquent | Relationship With And Where Clause Based On Foreign Column

Maybe try this

Group::where('visible',1)->with(['pages'=>function($q) {
   $q->where('visible', 1);
}])->has('pages', '>', 0)->orderBy('order', 'asc')->get();
Activity icon

Replied to Fetch Profile Data For The Profile View

the Auth::user() gives you the User model of the logged user, so I don't understand the problem here

Activity icon

Replied to Foreach Loop Is Deleting Me A Record !

Can we see the full controller ? Are you using an Observer ?

Sep
19
2 months ago
Activity icon

Replied to Sublime Text 3 Setup For Laravel

I think a lot of people here moved to Visual Studio Code or PHP Storm

Sep
18
2 months ago
Activity icon

Replied to How To Sort Outer Query Based On A Internal Query Field??

Try this maybe

DB::table('products')->join('reviews', 'products.id', '=', 'reviews.productId')->where('category_id', $category->id)->selectRaw('products.*, AVG(reviews.rating) as product_rating')->orderByDesc('product_rating')->get();
Activity icon

Replied to How To Prevent Specific Value In Validation

 'companyAddressId' => 'required|not_in:one,two',
Activity icon

Replied to Laravel Vapor Deployment Error

@jlrdw I tweeted him but no response yet

Activity icon

Started a new Conversation Laravel Vapor Deployment Error

Hi everyone,

I'm trying Laravel Vapor but I've got a weird problem. When I try to deploy my app I've got this error

  Loading composer repositories with package information                                                        
  Installing dependencies (including require-dev) from lock file                                                
  Package operations: 2 installs, 0 updates, 0 removals                                                         
    - Installing itconsulting/serveralerts (dev-master): Symlinking from ./nova-components/ServerAlerts         
    - Installing laravel/nova (dev-master): Symlinking from ./nova                                              
  Generating optimized autoload files                                                                           
  > Illuminate\Foundation\ComposerScripts::postAutoloadDump                                                     
  > @php artisan package:discover --ansi                                                                        
  The environment file is invalid!                                                                              
  Failed to parse dotenv file due to unexpected whitespace. Failed at...

Here is my .env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:y0vN7psAY3ZZpUmPoAu4n+699pxazQH4GuRyHcHR1+U=
APP_DEBUG=true
APP_URL=http://my-app.test

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=xxxxxxx

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PFKE_BASEURL="https://www.xxx.com/firms/"
PFKE_FIRM=00000
PFKE_USERNAME=99999
PFKE_PASSWORD=XXXXXXXXXXXXXXXXX
PFKE_USERAGENT="XX XXXXXXXXX ([email protected])"

GMOD_BASEURL="https://xxxxxx:5665/v1/"
GMOD_USERNAME=xxxxxxxxxxxx
GMOD_PASSWORD="xxxxxxxxxx"

I'm only able to deploy if all PFKE and GMOD keys are not in the .env file

Can you spot the problem here ?

Thank you

Activity icon

Replied to Many To Many Relationship Attach User When Creating A Project

Try this

$user->projects()->attach($project->id, ['field' => 'data']);
Activity icon

Replied to Store Data To Two Table From One Controller

You could add a method addDevice to your Sale model and then call it like

$sale->addDevice($device);

Sale Model

function addDevice($data) {
    $this->devices()->save(new Device($data));
}
Activity icon

Replied to Collect Data And Generate A Report

Pull the data from the database, put it on a view and transform this view into PDF with https://github.com/spatie/browsershot

Activity icon

Replied to Calculate Hours

If hour start and hour end are Carbon instance then you can calculate time like this

$payment->hour_start->diffInMinutes($payment->hour_end);
Activity icon

Replied to Laravel: Drag And Drop Fields Funtionalities.

I don't know premade packages like this.

Create your own around this maybe https://github.com/SortableJS/Sortable

Activity icon

Replied to @if En Una Vista

In english would have been better :p

It's probably not working because your query return an instance of Collection.

Try something like this

DB::table('providers')->where('id', $provider->id)->select('active')->first();

and then in you're if

@if($pro->active === "no")
...
@elseif($pro->active === "si")
...
@endif

p.s: @bobbybouwmann too fast :p

Sep
17
2 months ago
Activity icon

Replied to Send Data From Model To The Ajax In Laravel

Can you show us the error ?

Activity icon

Replied to How To Get Rating Average?

Let's try this (replace with good table name and field names)

DB::table('businesses')->join('reviews', 'businesses.id', '=', 'reviews.business_id')->groupBy('businesses.id')->selectRaw('businesses.*, AVG(reviews.rating) AS average')->orderByDesc('average')->get()
Activity icon

Replied to Validation: Class Users Does Not Exist

can you show us the whole method ?

Activity icon

Replied to Validation: Class Users Does Not Exist

  'email'     => 'required|email|unique:users,email'

for the unique rule you have to give the table (users) and the field (email)

Activity icon

Replied to Hello Upload Photo Not Found!

Can you show us the code ? Hard to help if we can't see anything

Sep
04
3 months ago
Jun
21
5 months ago
Activity icon

Replied to Uncaught ReferenceError: Require Is Not Defined In Vuejs Laravel

Show us the content of your JS file

Activity icon

Replied to How To Get Data From Database?

Is there any reasons not to user Eloquent models ?

By the way I don't really understand what you want to achieve here ? What's the problem ?

tips: the href in the a tag could be

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

Replied to Progressive Web Apps

That would be nice !

Activity icon

Replied to WhereNotIn & Where Methods Not Working When Combined

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

Activity icon

Replied to Dynamic Model Names

You could do

// $entity could be 'user' or whatever the model name

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

$model->first();
Activity icon

Replied to Best Practice To Implement Code Revision

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

Activity icon

Replied to Making My Class Instance Persistent Over Next Request

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

Activity icon

Replied to 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.

Activity icon

Replied to Login Over URL

You could 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

public 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);

    // Redirect
}
Activity icon

Replied to Authorization And Mysql Query

@jlrdw 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.

Jun
20
5 months ago
Activity icon

Replied to 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);
Activity icon

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