Ashraam

Ashraam

Web Developper at Ajaccio

Member Since 3 Years Ago

Ajaccio

Experience Points
76,200
Total
Experience

3,800 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
671
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
76,200 XP
Sep
27
2 weeks 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
3 weeks 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
3 weeks 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
4 weeks 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
1 month ago
Jun
21
3 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
3 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

Apr
22
5 months ago
Activity icon

Replied to Cannot Upload Laravel Project To Git

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

Activity icon

Replied to How To Allow Blade To Except (<a Href>, <br /> ... Etc)

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

Activity icon

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

Activity icon

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

Activity icon

Replied to PHP

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

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

Activity icon

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

Activity icon

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

Apr
21
5 months ago
Activity icon

Replied to Getting "Trying To Get Property Of Non-object" In Blade View.

Did you try to dd($club) and dd($club->president) in your controller first ?

Activity icon

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

Activity icon

Replied to Page Loads On My Machine But Return 500 Error Online

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

Activity icon

Replied to Trying To Get Property Of Non-object

@screwtape_mk Ok, nice you fixed it then :)

Activity icon

Replied to How To Apply Auth?

@aishahyaacob Good ! then mark the post as solved please :)