diegoaurino

diegoaurino

Member Since 1 Year Ago

web programmer at ~

Experience Points 154,140
Experience Level 31

860 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 1441
Lessons
Completed
Best Reply Awards 16
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.

20 Jun
4 days ago

diegoaurino left a reply on Extended Latin Characters Missing On Save() - Laravel 5.8

@RICHARDEV - Are you using any of the str* (string) PHP functions before saving? Take a look at the entire path before saving. Paste here this path.

Some PHP string functions use the current locale. That is one reason why some mb_str* variants exist. https://www.php.net/manual/en/ref.mbstring.php

19 Jun
5 days ago

diegoaurino left a reply on Extended Latin Characters Missing On Save() - Laravel 5.8

@RICHARDEV - I am not a specialist in Baltic charsets for MySQL. But I know that MySQL had some problems with those related collations in older versions. Looking at the docs, MySQL 8.* made some improvements: 

Language specific Unicode 9.0 collations for Czech, Danish (also valid for Norwegian), German (phonebook order), Esperanto, Spanish, Spanish (traditional), Estonian, Croatian (also valid for Serbian with latin characters, and Bosnian), Hungarian, Icelandic, Lithuanian, Latvian, Polish, Romanian, Slovak, Slovenian, Swedish, Turkish, Vietnamese, Japanese (including kana sensitive collation), Chinese, and Russian (also valid for Bulgarian).

What version are you using on your local machine? Try to update to 8.* if you are running an older one. Also, try to use a specific charset and collation offered by the 8.* version to see whether it works or not. https://dev.mysql.com/doc/refman/8.0/en/charset-baltic-sets.html 

It is also easy and fast to set up SQLite or PostgreSQL with Laravel. So, it is an option to isolate the problem.

diegoaurino left a reply on Extended Latin Characters Missing On Save() - Laravel 5.8

@RICHARDEV - Did you check the config/database.php file? Check the charset and collation keys in the connections array.

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
        ],
18 Jun
6 days ago

diegoaurino left a reply on Extended Latin Characters Missing On Save() - Laravel 5.8

Hello, @richardev !

Did you check if the specific table and column are using another charset? Perhaps this table (or column) is using utf8 instead. You can use `information_schema to accomplish it. Look: https://dev.mysql.com/doc/refman/8.0/en/information-schema.html 

Columns, tables, and schemas of each database can have a different collation and charsets. So, I suggest you give it a try.

Hope this helps you.

22 May
1 month ago

diegoaurino left a reply on PHPUnit Will Not Use :memory: Database

@NEXXAI - Are you running those tests from the command line? Take a look at this line in your error: "/Users/nexxai/.composer/vendor/phpunit/phpunit/phpunit:61" . It is using the phpunit globally installed in your machine for your user and not the one used by the app installation in vendor/bin/phpunit. The configuration I showed you above is all you need to run tests in memory. Thus, make sure both your application configurations and your local machine (PHP, composer, etc) are correctly set. Also, if you are running these tests from an IDE, you need to configure it there as well to point the phpunit.xml and the composer autoload correctly. Another thing I noticed is that your composer installation is not using the standard folder for Windows. Make sure your composer variables are correctly set for your system.

diegoaurino left a reply on PHPUnit Will Not Use :memory: Database

@NEXXAI - In other words, just append the following inside the php key of your phpunit.xml file:

 <env name="DB_CONNECTION" value="sqlite"/>
 <env name="DB_DATABASE" value=":memory:"/>

diegoaurino left a reply on PHPUnit Will Not Use :memory: Database

Hello, @nexxai !

You need to add the ":memory:" not in your .env file, but in the phpunit.xml file. Like this:

    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="MAIL_DRIVER" value="array"/>
        <env name="QUEUE_CONNECTION" value="sync"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>
        <env name="TELESCOPE_ENABLED" value="false"/>
 </php>

So,

 <env name="DB_CONNECTION" value="sqlite"/>
 <env name="DB_DATABASE" value=":memory:"/>

Let the .env file to set only your main databases.

That is more than enough. You can also use the RefreshDatabase trait to avoid database persistent changes. If you are just starting a new project, undo your configuration and start again to avoid misconfigurations.

That is all I do to run tests in memory.

Hope this reply helps you. Let me know if so.

diegoaurino left a reply on Feature Tests Do Not Work (404)

@PILAT - Hello, @pilat ! Hope you are doing great!

As I said, you need to set up your webserver properly to manage it. If you are using a shared hosting service and you don't have access to the webserver directives, contact the support. They need to hide your root folder, only expose your /public folder publicly and properly configure mod_rewrite, alias, etc. So, you will be able to use the http://MYSITE_REPLACED.info/back/ to access your application and the test should work by following http://MYSITE_REPLACED.info/back/api/vote, excluding the /public path. If you are unsure, do php artisan route:list to check your routes and API endpoints.

I do not recommend doing this only by changing your .htaccess. Both your main website .conf (if you are using Apache) and the .conf of the application in question need to be customized. Also, be aware that folders permissions and ownership need to be adapted to this situation.

Hope this reply helps you.

21 May
1 month ago

diegoaurino left a reply on Policy Always Returns 403

@THREEEL - I thought this was Laravel 0.1... Make sure there is no mistakes in the model and/or policies imports namespaces. Double check if your getEndpoint method is returning the correct path. Another point: your test says the "lectures" are open. So, you do not need a policy for the index. Do you? Also, take a look if other authentications, routes with the can key in the middleware method, gates or policies are not interfering in the process.

diegoaurino left a reply on Policy Always Returns 403

Hello, @threeel !

Also, try to change the protected $policies array. Instead of using the scope resolution operator to designate the class, like ::class, use the full autoload path, for example, 'App\Model' => 'App\Policies\ModelPolicy'.

Make sure your test method does not require authentication. If so, you need to authenticate first.

Hope this reply helps you. Let me know if so.

20 May
1 month ago

diegoaurino left a reply on WYSIWYG Image Upload

@MEMELE - Hello, @memele!

Are you using Jquery or Vue?

There is a package for Vue called vue-trumbowyg. I've used Trumbowyg before, but I found TinyMCE a much better option.

FileFieldName means the key expected by your $request->file('key').

For example,

$path = $request->file('image')->store($dir);.

A simple store method in your controller for image uploads would look like this:

    public function store(Request $request)
    {
        $dir = 'public/images';
        $path = $request->file('file')->store($dir);
        $name = str_replace("$dir/", '', $path);
        $response = [
            'success' => true,
            'url' => asset("storage/images/" . $name)
        ];

        return response()->json($response);
    }

This will return a response to your front-end with "url" and "success". You actually don't need to store the path in the database, since it will be stored in the body as a img tag that includes the src attribute.

The docs for Trumbowyng says it expects a JSON response like that.

{
    success: true, // Must be false if upload fails
    url: 'https://example.com/myimage.jpg'
}

So, my suggestion should fit your needs. Take a look: https://alex-d.github.io/Trumbowyg/documentation/plugins/#plugin-upload

Also, make sure you have properly set your back-end API to receive this post request.

Hope this reply helps you. Let me know if so.

18 May
1 month ago

diegoaurino left a reply on Laravel Resource Route

@RUSLANJOHNBELL - Hello, @ruslanjohnbell !

Check if your model IndividualCraftPerson is defining (or expecting) a different key for your model bidding. You can use dd($person) inside your show method to check if the model is properly injected.

I also suggest you paste both the related model and routes/api.php here. So, others can have a better idea of your problem.

Let me know if it helps.

diegoaurino left a reply on Laravel - Grouping Service Providers?

Hello, @h2onock !

I believe your controller is doing too much. I suggest you redesign your app a little bit. For example, since each user can have a single NewsProvider, you can create a Model where you can define the relationship and also set the default news channel. As you described, it looks like a simple one-to-many relationship. Then, in the front-end, you just need to fetch the "choice" made by the user.

To avoid the repetition on your "providers", you can apply the very basics principle of design patterns by separating what changes from what stays the same. To make it easier for you, you can put it in an interface or simply create a trait.

Then, create a separate controller to deal with each step.

Hope this reply helps you. Let me know if so.

17 May
1 month ago

diegoaurino left a reply on Feature Tests Do Not Work (404)

@PILAT - Hello, @pilat!

The test suite will not understand that it needs to follow this long path ( http://MYSITE_REPLACED.info/back/public/ ) to hit the API endpoints. You need to correctly define your root directory and your application directory on your web server. Then, set the application variables in the correct way.

Hope this reply helps you.

diegoaurino left a reply on Composer Laravel Installer Permission Denied On Windows 10

@PATRICKMACIEL - Hello, @patrickmaciel !

Could you show me your system and user variables? Follow the path I showed you in my comment above.

16 May
1 month ago
15 May
1 month ago

diegoaurino left a reply on RecursiveDirectoryIterator::hasChildren(): Open_basedir Restriction In Effect. File(/home/admin/web/connect.lightningwallet.online/public_html/phpsysinfo) Is Not Within The Allowed Path(s):

Hello, @coderathore !

It can be related to many different things. As I do not know much about your deployment setup, I would suggest the following:

  1. Check if the folder's permissions and ownership are properly set.
  2. Check if your web servers are configured to follow symbolic links in the correct way.
  3. Check if your base directory is not occulted to the web server or to the application.

Also check the PHP documentation to understand why this can be related to many problems in your deployment: https://www.php.net/manual/en/class.recursivedirectoryiterator.php

Give us more details and let me know if it helps.

diegoaurino left a reply on Composer Laravel Installer Permission Denied On Windows 10

Hello, @patrickmaciel !

I hope you installed Composer via the official ".exe" installer as @jlrdw suggested. But besides that, you also need to include the vendors/bin folder in your user path variable if you want to run the packages .bat from PowerShell or CMD with ease.

Go to system properties -> Advanced -> Environment Variables. In the variables for you user, append to the "path" variable something like %USERPROFILE%\AppData\Roaming\Composer\vendor\bin

If you did a custom/script installation, you need to define the COMPOSER_HOME variable as well. Look at the docs: https://getcomposer.org/doc/03-cli.md#composer-home

Let me know if it helps.

diegoaurino left a reply on Why Are My Tests Is Slower Than Jeffrey's Tests?

@UNTYMAGE - If you are working on projects that require Vagrant, run a single PHPUnit method at a time. Only run the entire suite to check if everything is okay.

Nowadays, I tend to simplify my environment as much as possible. I just use a simple and local PHP installation together with a MySQL server. I also recommend running tests on memory. Thus, when you run your tests, you never touch the MySQL service. For projects that require Unix tools, like Redis, I use it from WSL using the default ports.

If you need to make sure your app is compatible with your deployment machine, you can do that by creating a custom VM on Hyper-V (or VirtualBox) that matches your remote machine. In that case, you have an option to access your files via SSH or Samba. Even better, you can use some tools provide by big IDEs like PHPstorm to access it the same way we did in the old days by uploading via SFTP on save. Set git hooks to upload the files to the VM are also options.

I would stay with the local option. I have a long background in using Linux distributions, but I am very satisfied with Windows nowadays and, in some scenarios, it can be much faster than Linux.

14 May
1 month ago

diegoaurino left a reply on Why Are My Tests Slower Than Jeffrey's Tests?

Hello, @untymage !

Are you sharing folders between the Vagrant box and Windows?   This slowness is the case when you are sharing folders between different filesystems. There are some things you can do to optimize it, but it will never be as faster than running it on the same filesystem.   The docs for Homestead says the following:  

When using NFS on Windows, you should consider installing the vagrant-winnfsd plug-in. This plug-in will maintain the correct user / group permissions for files and directories within the Homestead box.

  Take a look: https://laravel.com/docs/master/homestead#configuring-homestead   The docs also say to specify the filesystem like:  

folders:
    - map: ~/code
      to: /home/vagrant/code
      type: “nfs”

  So check the plugins available for Vagrant. It will help a little.   If speed is important to you, install PHP directly on Windows to run it locally or put your projects inside the VM and access it remotely or via SSH or Samba share. Microsoft is customizing its own Linux kernel to be used on WSL2; so it will be an option for the future.   For now, a local Windows installation or a customized VM on Hyper-V is the best options.   Let me know if it helps.

diegoaurino left a reply on "You Need To Install The Imagick Extension To Use This Back End" - Cpanel Error

Hello, @aq1 !

We need more details about your deployment setup to help you.

For example, there is a package in Debian based distributions called php-imagick. When you install this package on Ubuntu, the system will automatically change your PHP configuration for you. You just need to reload your servers.

In case you have limited access to the server, things start to get complicated and you need to request support as @devfrey suggested. Other companies give you access to a "user-based" php.ini. So you need to check if it is available.

Let me know if it helps.

11 May
1 month ago

diegoaurino left a reply on Where Can I Find Created Custom Html Tags?

Hello, @francol !

Could you be more descriptive about your problem? Also, try to use Markdown; so it will be easier for others to read your code.

By custom "tags", do you mean Vue components? Vue components are located in the resource/js folder.

Check: https://laravel.com/docs/5.8/frontend#writing-vue-components

Let me know if it helps.

diegoaurino left a reply on Php Artisan Serve Not Working

As @jlrdw suggested, try php -S localhost:8000 -t public to see if the PHP built-in server can run your app, but point it to your public folder and not to your app root directory or app name.

In other words, go to your app folder and run the following command:

php -S localhost:8000 -t public/

Then open localhost:8000 in your browser.

Check: https://www.php.net/manual/en/features.commandline.webserver.php

If the command above works, chances are that the problem is in your artisan installation.

Also, check if ps aux | grep -i port and ps aux | grep -i artisan return something strange.

If the problem persists, I would suggest you delete and reinstall your vendors folder.

Let me know if it helps.

10 May
1 month ago

diegoaurino left a reply on Python Function Failing In PHP Exec()

@BENNYWALDEN - Hope you are doing great!

Is the problem solved? Where the script is located exactly? Check the file ownership with stat -c "%U %G" *.py to see if there is something strange.

One important thing is that the shell runs based on your .profile/.bashrc settings, your application does not, even when the user is the same in this case. It also means that your "PATH" is not accessible from the application when you run a script directly from the app. What you can do in this case is to run a subprocess from your user. But it is not a good practice since you are inside a web server.

Another point is that os.environ["PATH"] works differently in Windows. Thus, make sure your text editor is not kidding you. Check for proper imports and quotes.

Hope you solved the problem.

08 May
1 month ago

diegoaurino left a reply on Python Function Failing In PHP Exec()

Hello, @bennywalden

What OS are you using?

First, I would suggest you check your app rights to execute that script and access the directory where the script is in. For example, PHP runs as a www-data group if it is under Apache, etc. Also, make sure the script is executable by applying chmod +x *.py.

You can test both shell_exec() & exec(). The first one will "execute a command via shell and return the complete output as a string". Maybe it is what you really want. https://www.php.net/manual/en/function.shell-exec.php

You can use a shebang like #!/usr/bin/env python on the first line of your python script to specify your python environment. But #!/usr/local/bin/python2.7 would help you to specify the exact version you want to run.

Let me know if it helps.

07 May
1 month ago

diegoaurino left a reply on Homestead On Windows

Hello, @ronb1985 !

What OS are you using?

I suggest you check your guest and host folder permissions.

SSH into the VM and run the following commands on your project folder:

sudo chown -R :www-data storage bootstrap/cache

sudo chmod -R 775 storage bootstrap/cache

Let me know if it helps.

diegoaurino left a reply on Laravel 5.8 Permissions

Hello, @vandyczech !

I suggest you change your Apache conf to:


<VirtualHost *:80>
    ServerName <your domain or ip>
    ServerAlias <your www.domain>

    ServerAdmin <your email>
    DocumentRoot /var/www/friede/public

    <Directory /var/www/friede/public>
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

It is also important to check if your .htaccess is correct.

If your user is properly configured and secured, you can use sudo chown -R $USER:$USER /var/www to set the ownership of the www folder. Then add your user to the www-data group.

After that, run the following commands inside the /var/www/friede directory:

sudo chown -R :www-data storage bootstrap/cache

sudo chmod -R 775 storage bootstrap/cache

The "500 Internal Server Error" can be related to many things. So test this configuration first and let me know if it helps.

01 May
1 month ago

diegoaurino left a reply on Laravel Dusk Example Test Failing - Can't Load URL

@IVANMIRANDA - Glad to hear that! ;)

Please, make the thread as solved!

Bests,

29 Apr
1 month ago

diegoaurino left a reply on Pre Append Numbers To A Form Field Randomly

Hello, @glasstream2000 !

I am not totally sure what you really want, but you can use the PHP rand ( int $min , int $max ) : int function to generate a random integer. For example, rand(100,999) will return a 3 digit number.

Let me know if it helps.

diegoaurino left a reply on Error 404 On Audio/video Src Element

Hello, @shadorius !

It is hard to see the problem with the information provided. Start by checking your routes with php artisan route:list.

Bests,

diegoaurino left a reply on Laravel Dusk Example Test Failing - Can't Load URL

@IVANMIRANDA - Considering that the full path to your public folder is C:\www\laravel\public, add the following to Apache:


  DocumentRoot "C:\www\laravel\public"

  <Directory "C:\www\laravel">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
  </Directory>
 

I don't know what local web server solution are you using; so take this as a general guide. Also, check if mod_rewrite is enabled.

28 Apr
1 month ago

diegoaurino left a reply on Laravel Dusk Example Test Failing - Can't Load URL

@IVANMIRANDA - I believe that Dusk will not understand that it should follow this "http://localhost/public/" to access the application. If you are using Apache locally, you need to point the DocumentRootto the public folder of your app. Also check the AllowOverride directive and the mod_rewrite module are properly set.

Hope this helps.

diegoaurino left a reply on Laravel Dusk Example Test Failing - Can't Load URL

@IVANMIRANDA - Hello, @ivanmiranda ! Hope you are doing great!

You have mentioned that your app runs on http://localhost/etc. So, you APP_URL variable need to reflect that and not only http://localhost. What OS are you using? Is the app running fine? Is the problem only occurring while testing with Dusk?

27 Apr
1 month ago

diegoaurino left a reply on Default Register Route To Put Middleware. How To Do It

Hello, @jaikangam !

I believe you can get what you want by using authorization policies. Check the docs to see the difference between authentication and authorization: https://laravel.com/docs/5.8/authorization

Let me know if it helps.

diegoaurino left a reply on Laravel Dusk Example Test Failing - Can't Load URL

Hello, @ivanmiranda !

Just to make sure: have you set the APP_URL in your .env file?

Are you using php artisan serve or a local web server?

diegoaurino left a reply on Caching Views

Hello, @grestock !

Cache is stored in the storage/ folder. If blade was working fine on your local machine but on server it is not caching properly, chances are you need to review the permissions on the storage folder.

Check that other question where I helped a guy with similar problems: https://laracasts.com/discuss/channels/laravel/laravel-you-dont-have-permission-to-access-on-this-server

Let me know if it helps.

diegoaurino left a reply on HTML Debug / X-ray For Laravel/tailwindcss

Hello, @aurawindsurfing !

Do you know the Grid Inspector that comes with Firefox Developer Edition? https://mozilladevelopers.github.io/playground/css-grid/03-firefox-devtools

I think it is much better than the Chrome Grid highlight.

Hope it helps.

diegoaurino left a reply on Cookie Auth In API Routes

Hello, @mcardosob !

I believe what you are looking for is Laravel Passport. Check the following link: https://laravel.com/docs/5.8/passport#consuming-your-api-with-javascript

Let me know if it helps.

diegoaurino left a reply on Laravel You Don't Have Permission To Access / On This Server

@STEF - Hello, @stef ! Hope you are doing great.

Here are some steps you can follow:

  1. If you're accessing the server with the root user, stop doing that. Create a new user, grant it sudo/admin access and add it to the www-data group.
  2. Before SSH into the server with this new user, make sure both SSH server and Iptables are properly set.
  3. As I don't know how your application was deployed and what it was designed for, I will give you a general approach to set the ownership of the projects folder. In general, apps are under the /var/www on Debian based distributions. I hope your project is there. Otherwise, it can be under your $HOME folder. If your user is properly configured and secured, you can use sudo chown -R $USER:$USER /var/www to set the ownership. Then, go to your project root folder and do sudo chown -R :www-data storage bootstrap/cache.
  4. Use sudo chmod -R 775 storage bootstrap/cache to set the permissions recursively for storage and bootstrap/cache.

In general, that is it.

####Suggestions:

You also need to make sure the Apache DocumentRoot is pointing to the /public folder and the proper directives are set for the project directory. Otherwise, your configuration and environment files will be exposed and Apache will not be able to correctly follow the routes.

Let me know if it helps.

26 Apr
1 month ago

diegoaurino left a reply on Laravel You Don't Have Permission To Access / On This Server

Hello, @stef !

Do you only have access to your server via panel? It sounds like a permission problem. Make sure you have properly set the ownership and the permissions of your application folders and files. Also check the Apache directives and indexes.

Let me know if it helps.

24 Apr
2 months ago

diegoaurino left a reply on Passing The Api_token In Header When The User Log In

@EMFPC - Note that Laravel already comes with the header pre-configured for Axios.  Visite your r `resources/js/bootstrap file. You will see the following:


/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

/**
 * Next we will register the CSRF Token as a common header with Axios so that
 * all outgoing HTTP requests automatically have it attached. This is just
 * a simple convenience so we don't have to attach every token manually.
 */

let token = document.head.querySelector('meta[name="csrf-token"]');

if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}

Let me know if it helps.

diegoaurino left a reply on Passing The Api_token In Header When The User Log In

@EMFPC - I suggest you talk to the front-end developer to have a clear idea of the project architecture before implementing the API.

For example, if he or she will use Axios to communicate with the controller, I would suggest you set Laravel Passport because it will help you set the cookies for the API authentication with easy.  In other words, it is easier than you probably think. 

Check this link: https://laravel.com/docs/5.8/passport#consuming-your-api-with-javascript

diegoaurino left a reply on Moving The User Model File

@JAY_SINGULARA_TECH - There is a composer package called barryvdh/laravel-ide-helper. It would help you to optimize your PHPStorm for Laravel. Also check a PHPStorm plugin called "Laravel".

Good luck!

diegoaurino left a reply on Moving The User Model File

Hello, @jay_singulara_tech !

Are you using PHPStorm? If so, drag the file to the new directory. PhPStorm will show you the refactor options and where the model is in use.

In general, if you want to do it manually, you will need to update the namespace, like

namespace App\Models;

and update all the imports where the file is required. For example, in the RegisterController.php, update it to

use App\Models\User;.

Let me know if it helps.

diegoaurino left a reply on PHP Unit Not Catching Wrong Class Name On Dev?

@TENATIOUS - Since it is working on your (OSX) local machine, I would review your deployment process first.

Look for:

PHP version, LAMP/LEMP configuration, folder permissions, mandatory access controls, and so on.

diegoaurino left a reply on PHP Unit Not Catching Wrong Class Name On Dev?

@TENATIOUS - Have you checked your “storage” folder permissions on Linux?

23 Apr
2 months ago

diegoaurino left a reply on How To Use Api_token

@EMFPC - Hello, @emfpc !

For learning purposes, you can following these steps.

Create a middleware, for example:

php artisan make:middleware TokenAuth

In your new middleware and inside the handle method, add the following:


$token = $request->header('X-API-TOKEN');
if ('SOME_VALUE' != $token) {
    abort(401, 'Your token was not found!');
};
return $next($request);

Note: You can, for example, add Auth::onceBasic() to the if statement to add basic auth too.

In the kernel.php file, go to the middleware group section and look for 'api'. Add your new middleware at the end of the array. For example:


'api' => [
...
...
...

\App\Http\Middleware\TokenAuth::class
],

You can use a REST client app like Insomnia to check it by adding the token to the header. https://insomnia.rest/ Note that simple API_TOKEN and BASIC AUTH are insecure.

As @WebKenth suggested, you can use Policies to control user authorization. I think OAth 2 (with Laravel Passport) and Policies is the best solution for you.

Check: [https://laravel.com/docs/5.8/passport]

Let me know if it helps.

22 Apr
2 months ago

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

@LINK - Hello, @link !

In your resources/js/app.js file, do something like:


import Push from 'pushjs';

Then, you can use the library:


Push.create('Hello World!')

Let me know if it helps.

diegoaurino left a reply on Keyboard Shortcuts For Laravel App

Hello, @ ! Vue.js lets you create custom events: [https://vuejs.org/v2/guide/components-custom-events.html] [https://vuejs.org/v2/guide/events.html] Also, some of Vue key modifiers can be helpful: [https://vuejs.org/v2/guide/events.html#Key-Modifiers] Actually, there is a package called “VueShortkey” that have some of this functionally ready to use. [https://github.com/iFgR/vue-shortkey] When your front-end is ready, you can use Axios to communicate with your Laravel application. The good thing about this approach is that you can combine Vue reactivity with Laravel. Let me know if it helps.