starmatt

starmatt

Member Since 3 Years Ago

Paris

Student / Developer at 42 / Net&Work

Experience Points 9,770
Experience Level 2

230 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 38
Lessons
Completed
Best Reply Awards 8
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.

04 May
2 years ago

starmatt started a new conversation Request Not Passing Through My Middleware ? (5.4)

Hello everyone,

I have a bit of a middleware problem in 5.4

Picture this:

Route::prefix('{lang?}')->middleware('locale')->group(function() {

   Route::get('/', '[email protected]')->name('index');

   Route::middleware('auth')->group(function () {
       Route::get('account', '[email protected]');
       Route::get('account/infos', '[email protected]');
   });

   // ...
});

The locale middleware is used to prepend the right locale in the URL, for exemple site.com/fr/account or site.com/en/account when a user tries to access site.com/account. It works really well when a user tries to access a url with only one segment but when there is more than one segment (ie site.com/account/infos), the request does not even go through the middleware (if I dd() something on the first line of the handle() method I just get a 404), any idea why ?

The optional prefix lang is used to detect if the URL already has the locale or not, and if not, preprend it through the middleware and redirect to that.

Thanks for your help !

12 Apr
2 years ago

starmatt left a reply on Unable To Install

You can use Homestead on Windows as well

starmatt left a reply on Transfer Money To Users Using Stripe ?

Amazing, thanks dude!

starmatt started a new conversation Transfer Money To Users Using Stripe ?

Hello,

I am working on an app where I need to be able to transfer money to users. Would Stripe be able to do this ? The API documentation is confusing me on this... Any of you managed to do this in Stripe ?

Thanks for your attention, Matthieu

starmatt left a reply on How To Work With Long PHP Arrays In Laravel Views?

Yeah I know :) It would have to be a custom class, not something that's already part of Laravel. That's why it's up to you where to put it.

If you're new to php, check the video series here on Laracasts. If creating your own custom class is too complicated for you at this point I can give you an exemple you can use.

10 Apr
2 years ago

starmatt left a reply on I Can't Install Laravel 5.4

What command do you use to install laravel ?

starmatt left a reply on Cart Badge Not Incrementing

Well, if $this->items[$id] is null then it makes sense that the quantity never goes above 1. Try to figure out why it is null, I can't help more than that for now. Also, if it's supposed to be an array, you should initiate it as so:

public $items = [];

Last thing, you do this in your controller:

$oldCart = Session::has('cart') ? Session::get('cart') : null;
$cart = new Cart($oldCart);

Make sure the session is updated when you do

$request->session()->put('cart', $cart);

Put a {{ dump(\Session::all()) }} in your blade template so you can monitor the session.

starmatt left a reply on Cart Badge Not Incrementing

And if you add more than one of the same item ? Can you also dd($this->items[$id]) ?

starmatt left a reply on Combine Two Variable And Create New One ( Variable Variable ) In Blade Template

After playing around with the syntax, here's something that works:

$var = 'Un';
$var_en = 'One';

echo ${'var' . '_en'}; // outputs 'One';

So in your case :

{{ ${'v->vehicle->fuel_type' . $locale} }}

The second '$' is the problem in your exemple I think {{${'$v->fuel_type->vehicle_fuel_type'}.$locale}}, also you need to encapsulate both variables in brackets to have the intended variable name.

EDIT: to make this work with the object operator ->, you have to separate the variable and its attribute:

${'v'}->{'vehicle'}->{'fuel_type' . $locale}

starmatt left a reply on Combine Two Variable And Create New One ( Variable Variable ) In Blade Template

$v->vehicle->fuel_type

$v->fuel_type->vehicle_fuel_type

There seems to be something fishy here :p Shouldn't it be

{{${'$v->vehicle->fuel_type'}.$locale}}

starmatt left a reply on Cart Badge Not Incrementing

Yeah, $storedItem gets overwritten if the item has already been added:

if(array_key_exists($id, $this->items))
{
    $storedItem = $this->items[$id];
}

Try to dd($storedItem) after $storedItem['price'] = $item->price * $storedItem['qty']; ?

starmatt left a reply on Vuejs Events Not Firing When Used With Laravel Blade

You are still using mydata in your v-for, use the prop divisions instead. This should send an error in your browser console though... Do you check it ? Because it's there that the console.log('called') would appear as well.

starmatt left a reply on Php Error While Installation Of Laravel

Hm, you say you're on Ubuntu but mbstring.dll is a Windows dependency... which I think is weird :p

What you can try to do is:

  1. Open the php.ini file (depending on your setup, I'm sure where it is in Ubuntu, but something like /etc/php/{ your php version }/php.ini)
  2. Find the line that says ;extension=php_mbstring.dll
  3. Uncomment (remove the ; at the beginning of the line).
  4. Save, and restart your web server if necessary

starmatt left a reply on I Can't Install Laravel 5.4

What command do you use to install laravel ? Have you tried updating composer (composer self-update) ?

starmatt left a reply on Php Error While Installation Of Laravel

Also, is mbstring listed if you use the command php -m ?

starmatt left a reply on Toggle Method Not Working

auth()->user()->votes() returns a query builder, not the actual vote model. Try accessing it auth()->user()->votes instead, assuming the toggle method has been set in your model.

starmatt left a reply on Cart Badge Not Incrementing

It might be because qty is set to 0 every time you add an new item

$storedItem = ['qty' => 0, 'price' => $item->price, 'item' => $item];

so it doesn't go above 1 ?

starmatt left a reply on I Can't Install Laravel 5.4

Can you copy/paste the error output ?

starmatt left a reply on Php Error While Installation Of Laravel

What is the version of PHP you're using?

php -v in your terminal

starmatt left a reply on Vuejs Events Not Firing When Used With Laravel Blade

I would still like to know what is contained in this.mydata, try to console.log() it in your created() method. You haven't declared it the component's data(), so it might not be accessible.

data() {
    return {
        mydata = {}
    }
}

starmatt left a reply on Vuejs Events Not Firing When Used With Laravel Blade

What is $district ? I believe Laravel parses automatically when passing a variable in a Vuejs prop so you don't need the created() method. Do you have the Vuejs dev tools ? If so, you can check your components data from there and debug it accordingly.

starmatt left a reply on Vhost Family Laravel App With Private DB

You can set up more than one DB in your .env. So you could set a middleware or something that connects to right DB according to the subdomain name ?

06 Apr
2 years ago

starmatt left a reply on How Do I Return A Single Computed Value From A Collection?

I don't think there's a method to compute and affect one attribute of the collection.

Not long ago I ran into a similar issue and I was also looking for a collection method to do the loop for me. I was working with a collection of users and wanted to compute diffForHumans() on their created_at attribute but I still ended up with a foreach.

In the end, such a method would still need do loop internally, so there's little difference but a few lines of code less.

starmatt left a reply on Laravel 5.4 Combined Api Route Group With Auth Middleware?

For this to work you will need to add a api_token column to your users table.

This post is a very good read on the subject: https://gistlog.co/JacobBennett/090369fbab0b31130b51

I've followed this for a 5.4 app and it works.

starmatt left a reply on How Do I Return A Single Computed Value From A Collection?

Hm, a simple foreach would do ;)

With your exemple:

foreach ($this->dictionary as $key => $array) {
    $this->dictionary[key] = $this->doSomeComputation($array);
}

starmatt left a reply on How To Work With Long PHP Arrays In Laravel Views?

  1. Honestly I don't know much about SEO. But I can't think of why Google wouldn't cache it.

  2. That's up to you and what the architecture of your folders looks like. A default location could be in a Helper class, for instance in App/Helper/Helper.php. But again, that's up to you.

starmatt left a reply on How To Work With Long PHP Arrays In Laravel Views?

Well, you could save it to your database, and then access it via a model or the DB facade, or create a function somewhere that returns the array, so you can just call getMyArray() for instance to retrieve it in your application, a little bit like Laravel's config files.

starmatt left a reply on Saving An HTML Option List To DB - Laravel

No problem, make a habit of dd() or dump() your variables when you are not sure what they or they don't contain !

starmatt left a reply on Saving An HTML Option List To DB - Laravel

Well, you can see that active is present and its value is yes, is it what's intended ? You can now remove the dd() in your controller and check if it saves the active field now.

starmatt left a reply on How To Work With Long PHP Arrays In Laravel Views?

You need to store the array in the session.

You can accomplish this when rendering your view (in a controller method for instance).

return view('path.to.view', ['rows' => $array]);

Or via a redirect:

return redirect('/your-route')->with(['rows' => $array]);

Edit: not sure my answer is actually pertinent to your issue, I think I misread your question, my bad!

starmatt left a reply on Saving An HTML Option List To DB - Laravel

For your html:

<select name="active">
    <option value="yes" id="active" class="form-control">yes</option>
    <option value="no" id="active" class="form-control">no</option>
 </select>

And to check the values in the request, use the dd() function as shown in my first reply. Run your form and you'll see it displayed in your browser.

starmatt left a reply on Laravel 5.4 - Only User Model Is Saving With Empty Values To Database

Hm, is $childClass an Eloquent model ?

starmatt left a reply on Saving An HTML Option List To DB - Laravel

You don't need to use the name attribute on the option fields, just use it on the select field.

Also, you should check what it contained in the request:

 public function sstore (Request $request)
 {
    dd($request->all());

    ...
 }

starmatt left a reply on Laravel 5.4 - Only User Model Is Saving With Empty Values To Database

Can you also show us how you register a user ?

If you are doing it this way

$user = new App\User;
$user->name = 'John';
...

Don't forget to call the save() method to actually register the entry in your database

$user->save();

starmatt left a reply on StdClass Could Not Be Converted To Int

What is $nsscc ? Can you show us how you declare it ?

Without proper context it's gonna be pretty hard to find what's wrong.

starmatt left a reply on Building Auction Site With Laravel

If your question is about reactivity between the front and back end, check out the videos here on the Vuejs framework, Laravel actually ships with it out of the box.

05 Apr
2 years ago

starmatt left a reply on Validate Data Coming From My Own Application And Database

You can still use a validator !

Here's an example, I'll let you fashion it to match your own data:

// Create an array containing your data (basically like $request->all())
$data = [
    'name' => 'John',
    'email' => '[email protected]'
];

// Make the validator rules
$v = Validator::make($data, [
    'name' => 'required|max:255',
    'email' => 'required|email',
]);

// Validate your data
if ($v->fails()) {
    // Your data is not OK
}

// Your data is OK

More in the docs: https://laravel.com/docs/5.4/validation#manually-creating-validators

As to where to put it, that's up to you and your architecture, but I think validation logic has its place in a controller.

starmatt left a reply on Automatically Delete Blog Post When It Pass Its Expiry Date

Yeah, I think a cron job is the way to go with PHP... You could maybe make the check happen every hour but it would still not be right away.

starmatt left a reply on How Does Cache Driver Array Work?

From the docs: https://laravel.com/docs/5.4/session#driver-prerequisites

Data is stored a non-persisting PHP array, it is only meant for testing !

starmatt left a reply on Please Help NPM Install Failed

You shouldn't ssh into homestead to create a new project, it's just weird haha. Create the project on your host OS, set up homestead and run npm install from your host OS as well !

04 Apr
2 years ago

starmatt left a reply on How To Prefixing In Routes For Localization

I've implemented a system that looks like what you need.

Here's an example route group:

web.php

// Main GET routes with locale
Route::prefix('{lang?}')->middleware('locale')->group(function() {

    Route::get('/', function () {
        return view('index');
    });
});

The rest happens in a middleware:

App/Http/Middleware/Locale.php

<?php

namespace App\Http\Middleware;

use Closure;

class Locale
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if ($request->method() === 'GET') {
            $segment = $request->segment(1);

            if (!in_array($segment, config('app.locales'))) {
                $segments = $request->segments();
                $fallback = session('locale') ?: config('app.fallback_locale');
                $segments = array_prepend($segments, $fallback);

                return redirect()->to(implode('/', $segments));
            }

            session(['locale' => $segment]);
            app()->setLocale($segment);
        }

        return $next($request);
    }
}

I've set up some new keys in the config/app.php array:


    'locale' => 'fr',

    'locales' => ['fr', 'en'],

    'fallback_locale' => 'fr',

starmatt left a reply on Logout Doesn't Work

If you do

$ php artisan route:list

You'll see the correct route (hidden in the method Auth::routes() in web.php).

Now, to actually logout, everything happens in the frontend. Since /logout is POST only, you can for instance use a form:

<form action="/logout" method="POST">
    <input type="submit" value="Logout">
</form>

Trying to access /logout directly via your browser won't work because it sends a GET request.

Hope I made myself clear enough !

starmatt left a reply on Logout Doesn't Work

Since Laravel 5.3 I think, the /logout route is POST only. You're trying to access it via a GET request.

starmatt left a reply on OrderBy Failure With No Reason

Because all() returns a collection (like get()), and not a query (like where()), you can't use orderBy(). However you can use sortBy() or sortByDesc() from the collection object methods: https://laravel.com/docs/5.4/collections#method-sortby

So this would work:

$news = News::all()->sortByDesc('updated_at')->toArray();

Please think about formatting your answers with markdown next time (for readability!): https://help.github.com/articles/github-flavored-markdown

starmatt left a reply on Reading From A One-to-many Relationship Causing Errors

Again, it's in the docs: https://laravel.com/docs/5.4/eloquent-relationships#querying-relations

You can do this:

$children =  $parent->children()->where('foreign_id', $id)->get();

Where $parent is your parent model, and children() the relationship method you defined in your model. This will retrieve all children with a foreign_id matching $id.

starmatt left a reply on Reading From A One-to-many Relationship Causing Errors

I think the first problem is that you retrieve an array of collection with get(). You might want to use first() instead to retrieve the first row matching your query:

$test = \App\Album::where('name', 'Horrorscope')->first();

To retrieve a relationship from the parent model, you should use

$x = $test->artist;

This is going to link the child model as an attribute of the parent model, so:

$x = $test->artist;
return $x->name;

It's all in the docs! https://laravel.com/docs/5.4/eloquent-relationships

starmatt left a reply on Elimination Of Repeated Code

Maybe something like

$basics = $request->user()->basics()->where('user_id', $user)->first();

if ($basics) {
    // $basics exists
}

By using first() instead get() you will retrieve the first row matching your query, instead of an array, so you don't need to access $basics[0] in your return and just use $basics->id. Also, since you're going to return anyway, you don't need the else !

if ($basics) {
    // redirect to 'edit'
}

// redirect to 'create'