Demers94

Demers94

Member Since 3 Years Ago

Experience Points 37,350
Experience Level 8

2,650 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 264
Lessons
Completed
Best Reply Awards 10
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 May
1 month ago

Demers94 left a reply on Where() Clause Only When Value Is Not NULL

I don't know how to delete/close this post so I'll just leave this here

Turns out I can simply add a whereNull clause as well and it works fine

$models->where(function($query){
        $query->whereNull('ends_at')
            ->orWhere('ends_at', '>=', Carbon::now());
    });

Demers94 started a new conversation Where() Clause Only When Value Is Not NULL

Some models in my application have a ends_at column that can be null

I would like to fetch all the models that have a ends_at value greater than the current date, or that have NULL set as the value

Here is my current query :

$models = Model::where('ends_at', '>=', Carbon::now())->get();

However, this will only return models that have the ends_at field set. How can I include the NULL ones as well?

22 Apr
2 months ago

Demers94 left a reply on How Do I Access A Node Module?

How you use a package specifically depends on the package, usually you should be able to find usage instructions in the README file

Typically you'll start by doing a require/import in your code:

$ npm install package-name

import Package from 'package-name';
Package.doSomething()

Which package are you using exactly?

27 Feb
3 months ago

Demers94 started a new conversation Controllers Structure For API And "regular" Routes

I'm building an application where the the users can view job offers.

The /offers endpoint calls a controller method that shows the view with all the offers.

Route::get('/offers', '[email protected]');

public function index()
{
    return view('offers.index');
}

From the front-end, a Vue component makes an API call to fetch the latest offers.

What's the best approach regarding controllers structure for this case?

The way I see it I have three options :

  1. Call the same controller, same method and return a different response type depending on if the request was made via AJAX or not

    // Offers.vue axios.get('/offers').then(response => {...})

    // routes/web.php Route::get('/offers', '[email protected]');

    // OffersController.php public function index() { if(request()->isAjax()){ return Offer::get(); }

     return view('offers.index');
    

    }

  2. Call another method on the same controller

    // Offers.vue axios.get('/api/offers').then(response => {...})

    // routes/web.php Route::get('/offers', '[email protected]'); Route::get('/api/offers', '[email protected]');

    // OffersController.php public function index() { return view('offers.index'); }

    public function api() { return Offer::get(); }

  3. Call the index() method of a new controller specifically for API routes

    // Offers.vue axios.get('/api/offers').then(response => {...})

    // routes/web.php Route::get('/offers', '[email protected]'); Route::get('/api/offers', 'Api\[email protected]');

    // OffersController.php public function index() { return view('offers.index'); }

    // Api/OffersController.php public function index() { return Offer::get(); }

What is the best approach in this case?

I like #3 since it allows me to use only CRUD names for my controller methods and I don't have to pollute all the methods with the request()->isAjax() call, but I'm wondering if there would be another solution that would allow me to keep the code in the same place. I'm not convinced it makes sense to use different controllers like that for the same type of data.

28 Jan
4 months ago

Demers94 left a reply on Composer Very Slow On Windows

It's not @tomopongrac , I checked the php.ini file and the part about Xdebug is commented out. I also don't get a message saying that it's enabled when I run composer, which used to be the case a while ago when it was still enabled

Demers94 started a new conversation Composer Very Slow On Windows

For some reason running composer install is about 10x slower on Windows than on my Macbook. Xdebug is disabled, they're both using the same Internet connection so I'm not sure what could be causing this.

Also, when I SSH into a server from my Windows computer and run composer install on the server itself, it's much much faster, about the same as on the Macbook.

For reference, doing a composer installof all the dependencies on a new Laravel install (after removing /vendor) took 99.36s on the Windows computer and 9.56s on the Macbook

What could be causing this? Has anyone else encountered this issue?

Thank you for the help

08 Jan
5 months ago

Demers94 started a new conversation Displaying Paginator Links In Javascript

I'm making an AJAX call to my back-end to retrieve some resources. I want the results to be paginated because there are too many.

Is there a way to send the Pagination's HTML to the front-end via AJAX, so that I can display the page selection menu in my template?

Here's the code I'm using to retrieve the results :

$applications = Application::paginate();

        return [
            'results' => $applications->items(),
            'html' => $applications->links(),  
        ];

And here is my Javascript :

axios.get('/admin/applications/api').then(response => {
                    this.html = response.data.html;
                    this.applications = response.data.results;
                });

I can get the results just fine, but the HTML part is just an empty object.

Is what I'm trying to achieve possible at all?

Thanks!

26 Nov
6 months ago

Demers94 left a reply on Laravel Forge Support Email

Thanks @cronix , I've sent an email, hopefully they can help me sort that out

Demers94 left a reply on Laravel Forge Support Email

I can't login to my account at all. It asks for my 2FA verification code and I don't have it because I had to reset my phone a few weeks ago

As soon as I click "Login" and enter my information it asks for the code

Demers94 started a new conversation Laravel Forge Support Email

I'm having issues accessing my Forge account and would like to get in touch with their support to get this resolved.

I couldn't find any email address or link to a support system on the Forge website.

I found this on Google : https://forge.besnappy.com/contact

Is this the official support page?

Thank you for the help

24 Oct
8 months ago

Demers94 left a reply on Proper Way To Store Public Files

Thank you for the fast reply @Cronix

If I do that, two things happen :

  1. It now stores the file in /storage/app/articles instead of /storage/app/public/articles, so I can't access it via the symlink

  2. The path returned is still incorect, so I can't use it to display the file using the asset() helper method

Demers94 started a new conversation Proper Way To Store Public Files

Hi,

I'm trying to store an image uploaded by the user in the public folder so that it can be viewed by anyone, and save the path on the Article model.

Here is the code that I tried using first :

$path = request()->file('file)->store('public/articles);

This places the image in the /storage/app/public/articles folder as I expected, but the problem is that the path it returns is equal to public/articles/ABC123.png. After I created the symbolic link to my public folder, I can't retrieve the file by using the assets() method because the path is incorrect. It tries to find the file in /public/articles, but with the symlink it's in /storage/articles instead.

I now use this instead :

$path = request()->file('file')->store('public/articles`);
$path = str_replace('public', '/storage', $path);

If I do the above then I get the correct path, /storage/articles/ABC123.png and I can now use this to display the image.

Is this really the proper way to do things? It seems a bit weird to have to use str_replace() just to get a valid path. Is there a better way to achieve this?

Thanks for the help

14 Jun
1 year ago

Demers94 left a reply on Update Vue Object With Axios Response Data

Basically it would look something like this :

let self = this;

// ...

.then(function(response){         
     self.currentLog = response.data;
})
.catch(function(error){
    // Do something 
});
28 May
1 year ago

Demers94 started a new conversation Mailgun - Send Hundreds Of Thousands Of Emails

Hi,

We need to send a weekly newsletter to over 100K recipients.

I'm currently using Mailgun (which Laravel supports out of the box). I need to customize each email (language, custom unsubscription URL, etc). At the moment I'm creating a Job for each email and then processing the queue to send them, but this is extremely slow and inefficient.

How can I send thousands of custom emails using Mailgun?

I tried reading on Batch Sending on their documentation but it's not very good and created more questions than it answered.

Has anyone here done this before?

Thanks!

21 Mar
1 year ago

Demers94 left a reply on Table Sets By User, Access To Them

It sounds like multi-tenancy is what you want, there's two options :

1 - Use a seperate database for each tenant (company) 2 - Use the same database but add a tenant_id column to all of the tables

Both have their pros and cons. Here's the notes from Tom Schlick LaraconUS 2017's talk on muti-tenancy : https://tomschlick.com/2017/07/25/laracon-2017-multi-tenancy-talk

02 Feb
1 year ago

Demers94 left a reply on Font Awesome 5 Using Laravel-Mix On Laravel 5.5

@wilburpowery Probably because he's using the "SVG with JS" version of Font Awesome : https://fontawesome.com/get-started/svg-with-js

Demers94 left a reply on Taylor Otwell Cancelled My Account Without Asking Me

Why its provider fault and not your fault You create a script without taking into account various external factors And what is your excuse on that? I feel you just get the setup script from a online tutorial that works and tested in some major systems and then you have no clue how to administer and fix things But seems you cant understand that am trying to figure out why I am paying for your service. For a custom made script taken from an online tutorial? What is the support for? Explain

By the looks of it you have a very specific issue (with a custom VPS provider) and you failed to provide any valuable information to help them debugging. You expect them to "fix their issues" while only giving them generic and incomplete error messages.

It's hard to determine the tone of a written message accurately, but the quotes I posted above just scream entitlement and it's very easy to see why a customer service rep wouldn't want to deal with you anymore. You're just making assumptions and accusing them of a bunch of things.

It does sound like Forge is not what you're looking for, seeing as you think it's just "a bunch of pre-made command line scripts (like the ones on Digital Ocean tutorials)".

Just because you're paying for a service doesn't mean that you're entitled to express, custom support that will fix all of your issues for you. If you don't like the service and the support, speak with your wallet by unsubscribing instead of being rude to customer support that is just trying to help.

07 Dec
1 year ago

Demers94 started a new conversation Share Database Data To All Views From AppServiceProvider

Hello,

my app has two models : Domain and Region.

I want to share all the domains and regions (fetched from the database) with all the views, so I have the following code in AppServiceProvider's boot() method :

$domains = Domain::get();
$regions = Region::get();`

View::composer('*', function($view) use($domains, $regions){`
  $view->with('domains', $domains);
  $view->with('regions', $regions);
});

This works fine, however it will not work when I'm installing the repository (ex: on my server through Laravel forge) because the tables have not yet been created in the database when this piece of code is executed.

How can I fix this?

Thanks for the help!

13 Nov
1 year ago

Demers94 started a new conversation Promise-based Login Modal

Hello,

I'm using a VueJS component to show a modal and submit the form asynchronously when the users want to log in to my application.

In another page, there is a button that allows a user to do an action (apply on a job opening). When they click that button, a modal is opened and allows the user to select the resume that they want to use for the application. However, they must be logged in to do that.

What I would like to do is, when the user tries to apply while logged out :

1 - Show the login modal with a message that explains that they must log in to their account first in order to apply 2 - When the login is submitted and validated, and the user authenticated, show the first modal (where they can select their resume) without having to click on the button again.

I'm thinking that a promise-base approach would make sense here, but I really don't know where to start. I'm just not sure how to achieve this without relying on a lot of events everywhere, since there might be multiple scenarios where I want this functionnality.

Has anyone does this with VueJS and could help me get started? I try to find some code examples but I haven't seen anything that would work in this case.

Thanks a lot for the help!

18 Oct
1 year ago

Demers94 started a new conversation Localized Routes/URLs

Hi everyone,

I'm working on a bilangual app in both English and French. I would like to customize the route URL (that appears in the browser's address bar) so that it's localized based on the user's current language.

For example, the URL to access the contact page would be /contact-us in english and /nous-joindre in french.

I'm not sure what's way to approach this.

I tried defining custom config files and setting up the routes like that:

// EN config file
return [
    'routes' => [
         'contact' => '/contact-us',
    ]
];

// FR config file
return [
    'routes' => [
         'contact' => '/nous-joindre',
    ]
];

I then load the proper config file on a LanguageServiceProvider and put the result in the global config() store like so :

$configFile = require(base_path() . "/config/{$language}/app.php");
config(['configFile' => $configFile]);

This works for views, but whenever I try to access the config from the routes/web.php file I get null, it's not defined.

Is what I'm trying to achieve possible? Is there a better way to handle localization in routes URL?

Thanks for the help!

27 Aug
1 year ago

Demers94 left a reply on Some Users Posts Appear Twice

I hope Jeffrey Way makes an explanation video out of this bug

That would be nice to watch, see how he handles debugging and bug fixing :)

24 Aug
1 year ago

Demers94 left a reply on Nice User Notifications?

What you're looking for is the database notifications, as @Swaz said.

There are many drivers that you can use for a notification but the database one will just log it to a database table. From there, you front-end can make a request to an API endpoint that you defined and you can access the notifications of the current user :

Auth::user()->notifications

You can also fetch just the new, unread notifications :

Auth::user()->unreadNotifications

To mark them as read, you can do this :

$notification->markAsRead();

The code to display the notifications on the front-end or serve them from your backend doesn't ship with the framework, but all the functionnality is there for you to build your own. I'm sure you can find some packages for that.

02 Aug
1 year ago

Demers94 started a new conversation Disable Vue Development Mode Console Message

Hey,

in the console there's always this message from Vue :

Is there a way to disable it?

Thanks!

30 Jul
1 year ago

Demers94 started a new conversation Laravel Echo Not Receiving Broadcasted Notifications Via Pusher

Hi everyone,

I'm using Pusher and Laravel Echo to broadcast notifications (not events) to the front-end. The notifications is sent to Pusher (I can see the graph update in real-time as I send the notifications) and also appears in the database, but for some reason I can't receive it on the front-end using Echo.

Here's my bootstrap.js file :

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'my-key-here'
});

Here is the notification :

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class PostInFollowedTopic extends Notification
{
    use Queueable;

    public function via($notifiable)
    {
        return ['database', 'broadcast'];
    }

    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            'message' => 'Demo'
        ]);
    }
}

(I only kept the relevant code, I removed the constructor, toArray method, etc)

Here is how I'm trying to receive the notifications on the front-end :

Echo.private('App.User.1')
    .notification((notification) => {
        console.log(notification.type);
    });

I did uncomment the BroadcastServiceProvider in config/app.php :

App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,

I don't see any error in the console or in my application when I throw the notifications :

Route::get('/test', function(){
    Illuminate\Support\Facades\Auth::user()->notify(new App\Notifications\PostInFollowedTopic(App\Topic::first()));
});

The notification does show up in the database, so I'm assuming that there's no issue with this call.

Am I missing anything? Since it's showing up on the Pusher dashboard but not in my application, I'm assuming that there's something wrong with the way I setup Echo but I can't figure out the issue.

Thanks for the help!

27 Jul
1 year ago

Demers94 started a new conversation Laracon US Videos

Hi everyone,

I was away for the week so I couldn't attend the livestreamed version of Laracon US. Is there anywhere I can find the videos of the conference online?

Thanks!

07 Jul
1 year ago

Demers94 left a reply on Laravel Get Latest Reply From Topic

Sure, you can check that the lastPost exists before trying to get its user :

@if($topic->lastPost) {{ $topic->lastPost->user->name }} @endif 

That should work, but I haven't tried it myself.

The reason this never occured to me is that I take a slightly different approach, when a topic is created I make a new Post at the same time as the Topic is made, and that's where the information on the original post is stored (instead of having a body on both the Topic and the Post, like in Jeffrey's Forum series)

Demers94 left a reply on Laravel Get Latest Reply From Topic

Something along the lines of {{ topic->replies->sortBydesc('id')->first->user->username}} It makes sense to me.

What's wrong with that, it didn't work?

What I did is define a lastPost() relationship on my Topic model :

public function lastPost()
{ 
  return $this->hasOne(Post::class)->latest();
}
01 Jul
1 year ago

Demers94 left a reply on Custom Helper Classes In Laravel 5.4

What's wrong with doing it this way?

If I remember correctly I saw this method used in one of the video here on Laracasts, and I've seen this approach recommanded many times.

At the end of the day use what you want, but this works.

Demers94 left a reply on Custom Helper Classes In Laravel 5.4

What I usually do is ..

1 - Create the file (ex: helpers.php ) in the app/ directory

2 - Add that file to the autoloader in composer.json

autoload: {
  // ...
  files: [
    "app/helpers.php"
  ]
}

3 - Run composer dump-autoload in the command line

That's it, the new file will be autoloaded now.

24 Jun
2 years ago

Demers94 left a reply on 500 Error When Making POST Request, No Response

Edit: Fixed it, seems like there's a problem with how I'm setting up Sentry to report the errors :

public function report(Exception $exception)
{
    if ($this->shouldReport($e)) {
       app('sentry')->captureException($e);
    }   

    parent::report($exception);
}

If I comment out the first part with the if statement, it works, no Error 500 thrown anymore.

Demers94 started a new conversation 500 Error When Making POST Request, No Response

Hi everyone,

whenever I make a POST request in my application (from the front-end using Axios) I get a 500 Error in the console, and if I try to inspect the response I don't see the data.

Here's my .env file :

APP_NAME=Demo
APP_ENV=local
APP_KEY=base64:key-here
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://demo.dev

As you can see, APP_DEBUG is set to true, but despite that there is no response.

What am I missing?

Thanks!

21 Jun
2 years ago

Demers94 left a reply on How To Send Emails Without Any Services

Hi @Snapey , thanks for the fast reply!

I'm using Laravel Forge right now with Digital Ocean, do you know where I can find the crendentials and SMTP host to use?

I guess I could also use sendgrid or mailchimp, but it seems overkill to pay for a service like that only to send maybe a dozen emails per day

Demers94 started a new conversation How To Send Emails Without Any Services

Hi everyone,

I'm trying to send out a simple email without using any service (mailgun, mandrill, etc).

Here's my .env file :

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

It's the default mailtrap stuff, but I changed the MAIL_DRIVER to mail instead of the default smtp.

Whenever I try to send an email, the page just keeps loading until it times out.

What am I doing wrong? Do I need to use the PHP built-in mail() function instead of Laravel's Mail facade? Do I need to fill out some credentials for the username/password when using the default mail driver?

I read in the docs that Laravel is using SwiftMailer, but I can't find any information on how to actually use it.

Thanks for the help!

18 Jun
2 years ago

Demers94 left a reply on Any Easy Tutorials On Using Pusher For Laravel 5.4?

If you're using Laravel Echo it's pretty straightforward.

1 - Install Pusher PHP and set your ID/keys in the .env file

composer require pusher/pusher-php-server

2 - Set your BROADCAST_DRIVER in the .env file :

BROADCAST_DRIVER=pusher

3 - Create an event and have it implement the ShouldBroadcast interface

class SomethingHappened implements ShouldBroadcast
{
   // ...
}

4 - Define the channel that you want to send events to in the broadcastOn() method of your event

public function broadcastOn()
{
    return new Channel('demo');
}

5 - Install Echo on the front-end

npm install --save laravel-echo pusher-js

6 - Uncomment the Echo-related code in bootstrap.js, set your Pusher key

7 - Finally, get ready to intercept the event on the channel defined earlier (in broadcastOn method) on the front-end (ex: in Vue file, JS file, etc)

17 Jun
2 years ago

Demers94 left a reply on Using A Url Slug And Id On The Route

A simple alternative would be to append/prepend the ID to the slug when you are generating/saving it.

Ex:

$post->slug = $post->id . '-' . str_slug($post->title); 
// saved as 1-my-first-post

This solves your problem in the route since you can just do {slug} and don't have to worry about capturing the ID too

10 Jun
2 years ago

Demers94 left a reply on Validating Destroy Request

You could add your check just after the basic validation and before you actually delete the record :

if($class->students->count()){
  // Error, can't a class with students
}  

 // Later ...
 $class->delete();

You could also define a custom validation rule : https://laravel.com/docs/5.4/validation#custom-validation-rules

I've never used them so I'm not sure what the actual rule would look like though.

04 Jun
2 years ago

Demers94 started a new conversation Using SSH Keys On Windows

Hi everyone,

I've just started using Laravel Forge and am struggling with SSH keys on Windows. It works fine on my Macbook, I create the SSH key, add it to Forge and I can login.

On Windows, I'm using PuTTy to generate the SSH key and I've saved it in :

<username>/.ssh/rsa_id.pub

I've also added it to Forge without a problem.

However, when I'm trying to login using the command line, with ssh [email protected], I get this error :

Permission denied (publickey)

What am I doing wrong? Is this the right place to be storing SSH keys on Windows, or should I be using something else (different folder, different filename, etc)

Thanks for the help!

29 May
2 years ago

Demers94 left a reply on Is It Possible To Use Route Names (Laravel 5.4) With Axios?

You could also define your routes as a global Javascript object, defined in your master.blade.php or app.blade.php file :

<script>
  window.routes = {
    'users' : '{{ route('users') }}',
    'contact' : '{{ route('contact') }}',
  }
 
  // You can access it like this
  let route = window.routes.users
</script>
16 May
2 years ago

Demers94 left a reply on Why Isn't JQuery AJAX Used In Place Of Things Like Vue-resource Or Axios?

I still use jQuery's AJAX features whenever I work on a big project that uses jQuery, but for my new Laravel applications I'm trying to move away from it entirely, so I don't even pull in the library.

I like Axios' approach a bit better with the promises .then() and .catch() instead of just passing in closures to the function call.

Demers94 left a reply on Route Model Binding With 2 Models?

If the identifier that you use for your blogs and articles are different (ex: blog-123-123 and articles-123-123) then you can use a Regex so that certain routes are only triggered by the wildcards that match the format.

If that's not possible, then the other option would be to intercept everything that matches /{wildcard} in one route and in the closure do the necessary processing to dipatch the request.

11 May
2 years ago

Demers94 left a reply on Bulma How Do I Change The Primary Color?

I haven't used Bulma myself, but my guess is that you have to change the value of the $primary variable within the Bulma code itself, before the rest of the CSS is loaded and it's getting the value from that variable.

When you overwrite the $primary variable, it's already too late, all of Bulma's CSS has run and all the occurences of $primary were replaced by whatever value was set by the framework.

08 May
2 years ago

Demers94 left a reply on Custom Themes

Correct me if I'm wrong, but couldn't you simply handle this at the application level even though modules are not supported by the framework itself?

You could have a tables for themes/config, and when a theme is uploaded (CSS file or whatever format you want to use, in your application's dashboard) then it's inserted into that table.

On your master/layout blade file, if there's an entry for the theme in the database then you load the relevant CSS file right after the default one, so it overrides the styles. Anyone who wants to create a new theme can just make their own CSS file that overrides the default styles.

04 May
2 years ago

Demers94 left a reply on Vue Component Does Not Get Compiled Properly?

Thank you! But that is not what Jeffrey is doing in the series. I have followed his exact steps.

Look at the 5 minutes mark of the video you linked to, you can see him writing the code that was posted by @jbloomstrom , including the props: ['message'] part

02 May
2 years ago

Demers94 started a new conversation Syncing Vuex With The Backend

Hi everyone,

I'm building an online shop and using Vuex to manage the content of the shopping cart.

Here is my store at the moment :

const store = new Vuex.Store({
    state: {
        items: [
            {name: "iPhone 7"},
            {name: "Samsung Note 7"},
        ],
    }
});

And here's how I'm using it in my main component :

<ul>
    <li v-for="item in items">{{ item.name }}</li>
</ul>

computed: {
    items(){
        return this.$store.state.items;
    }
}

It works well with this very simple example, but it gets more complicated when I want to sync the cart content with the backend (since I'm storing the items in the session)

For example, when the page loads I want to load the existing cart content by querying the backend. Here's how I'm doing it right now :

// In app.js
created(){
    this.$store.dispatch('getCartContent');
}

// in the store
mutations: {
    getCartContent(state, data){
        axios.get('/api/cart').then(response => {
            state.items = response.data;
        });
    }
},

actions: {
    getCartContent(context){
        context.commit('getCartContent');
    }
}

This is still manageable, but it means that if I want to do anything else with the cart (add an item, remove an item, update the quantity), I need to :

1 - Create an action 2 - Create a mutation 3 - Dispatch the call to the action in my components (ex: to respond to a button click) 4 - Commit the mutation from the action

Is this really the good way to do it?

It doesn't feel right to have all these AJAX calls specific to the cart in my store, which as far as I understand is just a big object to store all your data. Why is this big object responsible for doing all the backend calls and processing that data?

Any help on how to improve this is appreciated.

Thanks!

01 May
2 years ago

Demers94 left a reply on The Scripts Didn't Work In Standalone.

Have you added the scripts ( https://github.com/JeffreyWay/laravel-mix/blob/master/docs/installation.md#npm-scripts ) to your package.json file, before running npm run watch (or whichever command you want)

"scripts": {
    "dev": "cross-env NODE_ENV=development webpack --progress --hide-modules",
    "watch": "cross-env NODE_ENV=development webpack --watch --progress --hide-modules",
    "hot": "cross-env NODE_ENV=development webpack-dev-server --inline --hot",
    "production": "cross-env NODE_ENV=production webpack --progress --hide-modules"
  }

I remember getting a similar error message when using standalone elixir without changing the scripts.

27 Mar
2 years ago

Demers94 left a reply on Navigation - Two Items 'active'

That's interesting, looks like it justs looks for shop in the URL to add the class, there's the same problem with every thread that has shop in the slug :P

Demers94 left a reply on [Socialite] How To Handle Providers That Don't Return The Email

Thanks @jekinney, that's a good idea.

Once you redirect them back to the page where they can supply their email to complete their profile, how do you link that data (when the form is submitted) with the OAuth data (provider name & identifier) that was returned by the OAuth provider before?

Let's say that I make a table social_logins with the following fields :

  • user_id (integer)
  • provider (string)
  • identifier (string)

If there's no email returned by the provider, I can create an entry with the user_id set to 0 or something, but later once they do provide that email, how do you link the new account with the social_logins entry?

Do you use a token that you pass to the "profile completion" view?

Demers94 started a new conversation [Socialite] How To Handle Providers That Don't Return The Email

I'm using Socialiate and SocialiteProviders to give our users a bunch of OAuth options.

Currently, when we login a user using a social provider, we attempt to find an existing user in our database matching that provider and ID combination. If there isn't, then we create the new account on the fly using the email address.

The issue is with the providers that don't return the email address, like Twitter and Steam. If we can't find an existing user with those credentials, then we have no way of creating a new account without an email address (and we don't want to make the email address optional/nullable).

What's the best way to handle this?

I was thinking of just showing the providers that support the email (like Facebook and Github) on the main login/registration page, and adding the other options on the user profile (so that they can link them to their existing account).

There must be a better solution, how do you guys handle this in your applications with Socliate?

Thanks for the help!

02 Mar
2 years ago

Demers94 left a reply on Syntax Error Or Access Violation: 1071 Specified Key Was Too Long

@Nicholas I saw that mentionned in the Github thread, but I'm running into this issue even with 5.7.14 and utf8mb4. I never managed to get it to work on any of my computers.

28 Feb
2 years ago

Demers94 left a reply on Upgrading To 5.4: Why Does Laravel Invent It's Own Urls ?? !!

The routes from Route::auth() are defined in Illuminate\Routing\Router.php, starting from line 994.