mariohbrino

mariohbrino

Member Since 1 Year Ago

Experience Points
74,800
Total
Experience

200 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
705
Lessons
Completed
Best Reply Awards
6
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 15
74,800 XP
19 Sep
1 day ago

mariohbrino left a reply on Best Database Management For Speed

Did you consider to use index in your columns?

mariohbrino left a reply on Collection Returning NULL Id's And Dates

You should use eloquent relationships.

In your model Request.php add the relationship frauds

public function frauds()
{
    return $this->hasMany('App\Fraud');
}

In your controller you can do this way

$request = Request::with(['frauds' => function ($query) {
    $query->whereNull('ip');
}])->orderBy('approved', 'asc')->orderBy('created_at', 'desc')->paginate(5);

https://laravel.com/docs/5.8/eloquent-relationships

09 Sep
1 week ago

mariohbrino left a reply on Big Project LARAVEL MIX Problem

I think you can add a new file at your resourses/js as admin.js and resources/css as admin.sccs. After you can add in your webpack.

mix.js('resources/js/app.js', 'public/js')
   .js('resources/js/admin.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css')
   .sass('resources/sass/admin.scss', 'public/css');

So you can import it in you admin panel.

04 Sep
2 weeks ago

mariohbrino left a reply on Slug Route Return 404

See on the documentation route > routing model binding > Customizing The Key Name.

https://laravel.com/docs/6.0/routing#route-model-binding

Add in your model this method.

public function getRouteKeyName()
{
    return 'slug';
}

Your route needs to follow the pattern.

Route::get('/news/{news}', '[email protected]')->name('news.show');

// or to all

Route::resource('/news', 'NewsController');

You don't need the slug in your controller anymore.

public function show(News $news)
{
    return view('news.single', compact('news'));
}
26 Aug
3 weeks ago

mariohbrino left a reply on Queue Jobs With Multiple Threads

@andresayej Thanks. I find out a solution based on your answer.

I can send it to different queues and run multiple workers to execute in different process.

mariohbrino left a reply on Duplicate Entry Issue With UpdateOrCreate

How is your validation? Are you validating the slug to check if it's unique?

public function rules ()
{
    'slug' => ['required', 'unique:table,column']
}

mariohbrino left a reply on Enable Remote Access To Database Without SSH

The database is in your ec2?

If so you will be able to access the database. Take a look on the link below.

https://vannstudios.com/connecting-mysql-database-engine-on-amazon-ec2-from-mysql-workbench

mariohbrino started a new conversation Queue Jobs With Multiple Threads

I have some jobs that the user requests and it will be executed in the queue with a gap of 1.5 seconds between each job.

I need to execute another job every 15 seconds to fetch some notifications in a RESTFUL API of the jobs that the user requested.

Solution I have so far was to add a fetch notification job between every 15 jobs that the user requested.

I would like to execute the fetch notification job as a background without inject it between the user jobs requested. Also it should not delay the jobs that the user requested.

24 Aug
3 weeks ago

mariohbrino left a reply on Laravel Excel

You can import over 1,000 rows with this package, I made over 10,000 rows with this package.

Create the class import to process the csv file

php artisan make:import NameImport

Import class

class NameImport implements ToCollection, WithChunkReading
{
    use Importable;

    public function collection(Collection $collection)
    {
        foreach ($collection as $item) {
            Model::updateOrCreate(
                [
                    // your identifier
                ],
                [
                    // your fields
                ]
            );
        }
    }

    public function chunkSize(): int
    {
        return 1000;
    }
}

Controller

public function upload()
{
    request()->validate([
        'file' => ['required', 'mines:xls,xlsx,csv,txt']
    ]);

    Excel::import(new NameImport(), request()->file('file'));

    return 'file uploaded';
}
22 Aug
4 weeks ago

mariohbrino left a reply on Laravel Excel

You can use this package, it's a good way to import and export data.

https://docs.laravel-excel.com/3.1/getting-started/

14 Aug
1 month ago

mariohbrino left a reply on Testing That A User Can Edit Profile

That's why you have the fillable in your model, to avoid that the user can change sensitive information. You need to know what you allow the user to do.

mariohbrino left a reply on Testing That A User Can Edit Profile

Since you are updating the current user profile, I dont think you should allow the user to pass the id.

You can fetch the current user and update what you need.

$profile = auth()->user()->profile();

Make sure that you have the relationship in your model to make it work.

// User.php

public function profile ()
{
    return $this->hasOne('App/Profile');
}

mariohbrino left a reply on Testing That A User Can Edit Profile

In your controller you are expecting a field as name, in your test you are passing a field as quote.

27 Jul
1 month ago

mariohbrino left a reply on How To Add My Toggle Data Into The Database Using Ajax. When I Click On Active Then My Row Is Affected With 0 And When I Click On Inactive Then My Row Is Affected With 1

You can cast your field status to boolean. Eloquent: mutators attribute casting

protected $casts = ['status' => 'boolean'];

Also add the field to your fillable property, it's about mass assignment. Eloquent: mass assignment

protected $fillable = ['status'];
15 Jul
2 months ago

mariohbrino left a reply on How To Show Count Of All Subject With Slug From Post Table?

Sorry about that the correct relationship.

Subject.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Subject extends Model
{
    /**
     * Get the subjects of post.
     */
    public function posts()
    {
        return $this->hasMany('App\Post');
    }
}

Fetch all results with count

$subjects = App\Subject::withCount('posts')->get();

foreach ($subjects as $subject) {
    echo $subject->posts_count;
}

mariohbrino left a reply on How To Show Count Of All Subject With Slug From Post Table?

You can use eager loading to fetch the data, also you can use counting related models.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    /**
     * Get the subjects of post.
     */
    public function subjects()
    {
        return $this->hasMany('App\Subject');
    }
}

Fetch all results with count

$posts = App\Post::withCount('subjects')->get();

foreach ($posts as $post) {
    echo $post->subjects_count;
}

https://laravel.com/docs/5.8/eloquent-relationships#counting-related-models

mariohbrino left a reply on Pass Array From Child To Parent

You can use props to share data between your child component, also you can use emit event to share the data with your parent component.

ProductCart.vue

<script>
    props: ['source']

    export default {        
        data() {
            return {
                products: this.source
            }
        },

        methods: {
            submit() {
                // ajax request
                this.$emit('save', data);
            }
        }
    }
</script>

WorkSheet.vue

<template>
<div>
    <product-cart :source="products" @save="save"/>
</div>
</template>

<script>
    import ProductCart from './ProductCart';

    export default {        
        components: {
            ProductCart
        },

        data() {
            return {
                products: []
            }
        },

        save(data) {
            // do something
        }
    }
</script>

mariohbrino left a reply on Set Radio-button Value By Bool In Array

You can use a current option variable and a watcher to set the value in your array of objects.

new Vue ({
    el: '#app',

    data () {
        return {
            selected: null,
            options: [
                {"id": 1, "title": "Car", "value": false},
                {"id": 2, "title": "Bike", "value": false },
                {"id": 3, "title": "Bus", "value": false},
            ]
        };
    },

    watch: {
      selected(selected) {
        this.options.forEach((option, index) => {
          option.id == selected ? option.value = true : option.value = false;
        });
      }
    }
});
<div id="app">
    <div v-for="(option,index) in options" :key="index">
        <input 
            type="radio"  
            :id="index" 
            :value="option.id" 
            :name="'option-selected'"
            v-model="selected">
        <label :for="index">{{ option.title }}</label>
    </div>
    {{ options }}
</div>

mariohbrino left a reply on Set Radio-button Value By Bool In Array

I think would be better you have another variable that you set your current option.

Remove the field value in your options and add variable selected.

new Vue ({
    el: '#app',
    data () {
        return {
                selected: null,
            options: [
                {
                        "id": 1,
                        "title": "Car"
                },
                {
                        "id": 2,
                        "title": "Bike"
                },
                {
                        "id": 3,
                        "title": "Bus"
                },
            ],
            };
        },
    });

In input :value change to option.id and the v-model change to selected

<div id="app">
    <div v-for="(option,index) in options" :key="index">
        <input type="radio"  :id="index" :value="option.id" :name="'option-selected'" v-model="selected">
        <label :for="index">{{ option.title }}</label>
    </div>
     {{ selected }}
</div>
23 Apr
4 months ago

mariohbrino left a reply on Tinker Not Working

Which php version are you using?

It can be related about php version 7.3. You can install php version 7.2 or lower and it will work fine.

13 Feb
7 months ago

mariohbrino left a reply on Convert This Query To Eloquent

Here is an example of how you can do this, this is standardized for laravel.

Migrations - designations and employee_details

Schema::create('designations', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->timestamps();
});

Schema::create('employee_details', function (Blueprint $table) {
    $table->increments('id');
    $table->unsignedInteger('designation_id');
    $table->timestamps();

    $table->foreign('designation_id')
        ->references('id')
        ->on('designations')
        ->onDelete('cascade');
});

Models - relationships one to many

class EmployeeDetail extends Model
{
    protected $table = 'employee_details';

    public $fillable = [
        'designation_id'
    ];

    public function designation() {
        return $this->belongsTo(Designation::class);
    }
}

class Designation extends Model
{
    protected $table = 'designations';

    public $fillable = [
        'name'
    ];

    public function employee_details() {
        return $this->hasMany(EmployeeDetail::class);
    }
}

Controller - DesignationController

public function index()
{
    return Designation::select('name')->withCount(['employee_details'])->get();
}

// return [ {"name": "Test', "employee_details_count": 2} , ...]
11 Feb
7 months ago

mariohbrino left a reply on Upload Multiple Images

Follow the link below of article where explain how you can do it.

Medium

mariohbrino left a reply on Pixel Measuring Tool

Yes, it's correct.

You can select a region of the screen by pressing cmd+shift+4 and then holding the cursor pressed while dragging it around. Without releasing the cursor, it makes for a convenient screen ruler that can be opened quickly up at any time. By releasing it you will take a screenshot or you can dismiss it by pressing the Escape key.

Link

04 Feb
7 months ago

mariohbrino left a reply on How Can I Make This Api To Display In The Browser

You can use eloquent relationships. Laravel eloquent relationships

model - add the relationship on your model Property

public function category()
{
    return $this->belongsTo(Category::class);
}

controller - by default laravel return json

public function index()
{
    $property = new Property();
    return $property->with('category')->get();
}

or

public function index()
{
    return Property::with('category')->get();
}

In case you need to pass more than one relationship, you can pass a array

public function index()
{
    return Property::with(['category', 'other-method'])->get();
}
03 Jan
8 months ago

mariohbrino started a new conversation Artisan Tinker Exit Without Error Message

I was using artisan tinker normally and now it doesn't work any more. I can get inside but on the first command it exit without any message error. Somebody did have this issue before? Any suggestions?

mariohbrino test $ php artisan tinker
Psy Shell v0.9.9 (PHP 7.3.0 — cli) by Justin Hileman
>>> $user = new App\User();
mariohbrino test $ 

Thanks. Regards.

13 Nov
10 months ago

mariohbrino left a reply on Missing Origin Validation In Webpack-dev-server

Any solution on this? I couldn't find a solution yet.

27 Oct
10 months ago

mariohbrino left a reply on Larave Spark To Define Which Users Can Create Team

@cmackinlay

You need to define where you want to apply the middleware, in this case I did apply into a group middleware web.

You can add the path of your middleware into app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        \\ ------ code above ------
        \App\Http\Middleware\VerifyUserCanCreateTeam::class,
    ],
]
26 Oct
10 months ago

mariohbrino left a reply on Larave Spark To Define Which Users Can Create Team

@Cronix

I found out what was missing with your instructions, thank you.

mariohbrino left a reply on Larave Spark To Define Which Users Can Create Team

@Cronix

I add a field into table users to check if the user can create a team, and use a middleware to set the method Spark::noAdditionalTeams, but it doesn't work.

Do you know how can I make it work? Thanks.

if(\Auth::check() && ! $request->user()->create_team && ! Spark::developer(\Auth::user()->email)) {
      Spark::noAdditionalTeams();
}

mariohbrino started a new conversation Larave Spark To Define Which Users Can Create Team

There is a method I can use to define if the users can create teams named noAdditionalTeams, which it can be add at SparkServiceProvider.php to define all users cannot create a team.

There is a way to I define which user can create team or cannot?

19 Oct
11 months ago

mariohbrino left a reply on Spark 7.0 Error With Route Model Binding

@Cronix

Thank you.

That worked and is what I needed in the begin. I was thinking and looking for a way to make it generic as well, so I do not have to create a new one for each model. Do you have one idea how to apply to all models?

Thanks.

18 Oct
11 months ago

mariohbrino left a reply on Spark 7.0 Error With Route Model Binding

@Cronix

Thanks, I forget to say that, I saw that before. But, I don't want to do it for each route I have, in case I forget it will be bad.

There is a case when I'll use resource, and this function where is not option for resource routes.

Route

Route::resource('/api/user', 'UserController');

Controller

public function show(User $user) {
    return $user;
}

mariohbrino started a new conversation Spark 7.0 Error With Route Model Binding

I have one issue with Laravel Spark 7.0, the route model binding doesn't abort when it passes a string. It works fine at Laravel 5.7, only in Spark it happens.

Any one can help me with this? Thanks.

Route

Route::get('api/users/{user}', function (App\User $user) {
    return $user->email;
});

Example: app.local/api/user/test

Result

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "test" (SQL: select * from "users" where "id" = test limit 1)
18 Sep
1 year ago

mariohbrino left a reply on How Can I Define A Route That Doesn't Redirect To Team Missing Page

@bobbybouwmann thank you, I did as you suggested, but it keeps happening on redirect me to team/missing. So I noticed that the route was with middleware set by default.

The route web have been set by default the middleware hasTeam, with that in mind I can made my own route admin. Laravel Spark changes the default web route and add a middleware hasTeam. Check the RouteServiceProvider file in app/Providers/RouteServiceProvider.php

protected function mapWebRoutes(Router $router)
    {
        $router->middleware(['web', 'hasTeam'])
               ->namespace($this->namespace)
               ->group(base_path('routes/web.php'));
    }
17 Sep
1 year ago

mariohbrino started a new conversation How Can I Define A Route That Doesn't Redirect To Team Missing Page

When I define the user CanJoinTeams the middleware VerifyUsersHasTeam redirect the user to a team\missing, because I don't have a team setup. I want to find a way to bypass the team verification for the admin. Is that possible?

Thanks.

mariohbrino left a reply on Sh: Composer: Command Not Found

I was been install the composer as /usr/local/bin/composer/composer.phar when I should to install /usr/local/bin/composer that's why the alias did not work.

Install and setup composer into /usr/local/bin with name composer

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Add alias into ~/.bash_profile

alias composer="php /usr/local/bin/composer"

13 Sep
1 year ago

mariohbrino left a reply on Sh: Composer: Command Not Found

I did install composer in my macOS 10.13.6 and follow the instructions you guys give, but I still don't have access to composer when I use alias without file composer.phar.

Please, can someone help? Thanks.

  • [x] Install composer
  • [x] Move composer to /usr/local/bin/composer
  • [x] Add alias into ~/.bash_profile
  • [x] Test commands
# Install
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
# Move
mv composer.phar /usr/local/bin/composer

Add alias with file composer.phar into ~/.bash_profile

alias composer="php /usr/local/bin/composer/composer.phar"

Running

composer --version

generates this response

Composer version 1.7.2 2018-08-16 16:57:12

Running

laravel new project-name

generates this response

Crafting application...
sh: composer: command not found
Application ready! Build something amazing.

Change alias without file composer.phar into ~/.bash_profile

alias composer="php /usr/local/bin/composer"

Running

imac server $ composer --version

generates this response, no action

imac server $

Running

imac server $ cd project-name
imac server $ composer install

generates this response, this don't install any dependencies

imac server $
18 Aug
1 year ago

mariohbrino left a reply on Package Composer Psr-4 Autoload Class Not Found

I found my mistake, my path was wrong.

Wrong: "scr/"

"autoload": {
    "psr-4": {
      "Footer\": "scr/"
    }
  }

Correct: "src/"

"autoload": {
    "psr-4": {
      "Footer\": "src/"
    }
  }

mariohbrino started a new conversation Package Composer Psr-4 Autoload Class Not Found

Please can someone help?

I want to make a package test, I did create a composer package dependency. The error message when I import it to my project is Class 'Footer\Foo' not found.

  • Package create test

I did put this dependency into my vendor and run:

    composer dump-autoload

Folder structure

    .
    ├── ...
    ├── vendor
    |   ├── mariohbrino
    |       ├── footer
    |           ├── src
    |               ├── classes
    |                   ├── Whatever.php
    |               Foo.php
    |       ├── composer.json

src\classes\Whatever.php

<?php

namespace Footer\Classes;

class Whatever
{
    public function build(){
        echo 'called';
    }
}

src\Foo.php

<?php

namespace Footer;

use Footer\Classes\Whatever;

class Foo extends Whatever
{
    public function __construct()
    {
        $this->build();
    }
}

composer.json

{
  "name": "mariohbrino/footer",
  "type": "library",
  "description": "Package test",
  "homepage": "http://github.com/mariohbrino/footer",
  "keywords": ["Package", "Test"],
  "license": "MIT",
  "minimum-stability": "dev",
  "authors": [
    {
      "name": "",
      "email": ""
    }
  ],
  "require": {
    "php": ">=5.5.0"
  },
  "autoload": {
    "psr-4": {
      "Footer\\": "src/"
    }
  }
}