murilo

murilo

Member Since 3 Years Ago

Ribeirão Preto

Experience Points 29,540
Experience Level 6

460 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 252
Lessons
Completed
Best Reply Awards 0
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.

04 May
2 weeks ago

murilo started a new conversation Form Validation Rule When Updating Pass ID Value

hello , I have a a question about form Validation Rule . Can I pass more than one value to this class ? My Rule validation class , verify -

IF IS CREATING -
* If it has NOT other product with the same title .

IF IS UPDATING -
* If it has NOT other product with the same title .
* if is the same ID of the product that I am updating  , IT will not verify if has the same title of that product .

I wold Like to pass the ID , when I update .

I have form request like this -


use App\Rules\VerifyTitleExists;

... 

 public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'title'               => [ 'required' , new VerifyTitleExists ] ,
            'price'               => 'required' ,
            'category_id'         => 'required' ,
        ];
    }

And a Rule Validation -

use App\Product;

     public function __construct()
    {
        //
    }

    public function passes($attribute, $value)
    {
    
    // how could I get this $id value ?         

    // IT IS UPDATING 
    if($id){

           return Product::where('title' , $value)->where('id' , '!', $id)->first() ?  false
                                                                                                  :  true;  

    }

    // IS CREATING
        // IF TITLE EXISTS RETURN FALSE
        return Product::where('title' , $value)->first() ?  false
                                                                           :  true;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'This Title  Already Exists , Chose Another One ';
    }


WHat wold be the best whay to do that ?

Thanks

03 May
2 weeks ago

murilo left a reply on I Cant Connect Mysql .env Production

Thanks @jlrdw , It is working now . I found the error

I created a new user , now like this -


CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'js7634ld';
GRANT ALL PRIVILEGES ON *.* TO 'new_user'@'localhost' WITH GRANT OPTION;


after a new db

CREATE DATABASE new_db;
USE new_db;

Now it is working , thanks

murilo left a reply on I Cant Connect Mysql .env Production

hello @jlrdw . if I try to make the migration . It gives this error -

SQLSTATE[HY000] [1045] Access denied for user 'm_user1'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = post_test and table_name = migrations)


 PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'm_user1'@'localhost' (using password: YES)")
      /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=localhost;port=3306;dbname=post_test", "msantos", "hsd", [])
      /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70


murilo started a new conversation I Cant Connect Mysql .env Production

Hello , Please . some one can help me ? I am trying to deploy a website in this server - vultr.com .

Well , I had donne everthing correctly , but It is not connecting to database . I using Nginx / Laravel 5.8 / PHP 7.2

this is my .env

APP_NAME=Laravel
APP_ENV=production
APP_KEY=base64:gyo6oWaubavzqyQNRfH9TEvn0Pbnmfg2345Slfo=
APP_DEBUG=false
APP_URL=http://144.202.33.87

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=post_test
DB_USERNAME=m_user1
DB_PASSWORD=hHHkd123


this is the log error -

    [2019-05-03 21:37:24] production.ERROR: SQLSTATE[HY000] [1045] Access denied for user 'm_user1'@'localhost' (using password: YES) (SQL: select count(*) as aggregate from `posts`) {"exception":"[object] (Illuminate\Database\QueryException(code: 1045): SQLSTATE[HY000] [$
[stacktrace]

I can access this database using

     mysql -u m_user1 -p 'post_test'

and after , type my password . I access successfuly .

my database is like this -

+----------------------+
| Tables_in_post_test  |
+----------------------+
| post_categories      |
| posts                |
| migrations           |
+----------------------+
3 rows in set (0.00 sec)

But I cant connect , with laravel . maybe my .env is rong . do I use APP_ENV=production ?

I alredy tried -

php artisan config:cache
php artisan dump-autoload
php artisan config:cache
php artisan route:clear

18 Apr
1 month ago

murilo left a reply on Cloning My Project , NPM Is Not Rendering All The Js Code Properly

Hello Guys , I solved the problem , after 2 days trying many ways , now it is working . I just copped the the node_modules , folder from the old project into the new one .

@siangboon , I did like that - I just installed the same version of laravel , copped all those folders that I had in the last project . and copped as well the - node_modules Folder , and I did the command -

    npm run dev

so now It is working . Thanks every one .

17 Apr
1 month ago
16 Apr
1 month ago

murilo started a new conversation Cloning My Project , NPM Is Not Rendering All The Js Code Properly

Hello Guys , I have a problem here that I dont know how to solve . I have a website that I created , It is in laravel 5.6 and VUE js , if I try to render the javascript code in this folder , it will render properly , I can render by this command -

    npm run dev 

well , I recently tried to clone this project in other machine , I created succesfuly , but the javascript is not rendering properly .

Then I created a new project in my machine , and copied the same project , the same version of laravel , same version of npm , and cloned the project , and it gave the same error when I tried to render by this command -

    npm run dev

It does not gives any error , but it is not render properly some codes , that are more complex . I dont know what is happening , had this happed with some one ? I dont know what to do .

31 Mar
1 month ago

murilo started a new conversation NPM Run - Is Not Creating A JS File

Hello GUYS , I have been all day trying with many ways to solve a problem . I have a project that I created inside XAMP Host ( in my machine , windows ) , then I started working with docker ( Laradock ) and I created the same project inside the laradock host .

Well , it is working , but when I created the Javascript with -

npm install
npm run dev

It seens that some classes in javascript was not rendered properly , javascript classes like this ones -

https://laracasts.com/series/learn-vue-2-step-by-step/episodes/20

It is not working properly , I am using -

npm vesion - 6.7.0
node version - 11.12.0

maybe , it is rendering in a strict mode , does have any configuration that I set strict or not strict ?

Thanks a lot

16 Mar
2 months ago

murilo left a reply on Detect Outside Event Does Not Work Inside VUE Modal

I realized that happens becose I used this function inside VUE Modal -

@click.stop

<div class="modal-wrapper"    @click="$emit('close')" >

                                    <div :class="modalStyle" @click.stop >

                    ....
                    </div>

</div>

To detect when click outside the modal - close the modal . I fixed thanks ,

murilo started a new conversation Detect Outside Event Does Not Work Inside VUE Modal

Hello guys , I did a drop down compoennt that open , if click inside and close if click outside . I used this function to detect INSIDE / OUTSITE -

https://jsfiddle.net/Linusborg/yzm8t8jq/

this is the image of my component - https://ibb.co/WxVPrCY

It works , but I tried to use this inside VUE Modal , and this function to detect inside / outside the compoent , does not work inside the VUE modal .

I wold like to detect a click inside the VUE Modal , but NOT inside my component , or outside the component . Does any one there had the same problem ?

Thanks

29 Dec
4 months ago

murilo started a new conversation Count Posts Where Tag = 1

Hello , I have a question .

I have this code , It is working -

CATEGORY CONTROLLER

       return  CategoryPost::select(['id' ,'title'])
        ->withCount('Posts')
->get();

CATEGORY MODEL

  public function Posts(){
        return $this->hasMany(Post::class , 'category_id' );
    }

BUT I want to count all the posts in this category with TAG = 1 .

It wold be something like that -

CATEGORY CONTROLLER

       return  CategoryPost::select(['id' ,'title'])
        ->with('CountPostWithTagOne')
->get();

CATEGORY MODEL

  public function Posts(){
        return $this->hasMany(Post::class , 'category_id' );
    }

  public function CountPostWithTagOne(){
        return $this->Posts->where('tag_id' , 1 )->count();
    }

But this second example does not work .

19 Dec
5 months ago

murilo left a reply on Searching , And Change The Result / Json Decode .

@REALRANDYALLEN - Hello @REALRANDYALLEN , not realy , I have more Items in this query . It wold be betther that I could keep the eloquent structure . but was a good Ideal . Thanks

murilo started a new conversation Searching , And Change The Result / Json Decode .

I dont know if this is possible , I am getting a Json decode search and using this VUE js . like this -

  $post = Post::select(['id', 'status' , 'title'  , 'description'])->get();

   return response()->json([ $post ]);

I wold like to change my search , using -


str_limit('description', 40) in the description field

something like that -


  $post = Post::select(['id', 'status' , 'title'  , str_limit('description', 40) ])->get();

   return response()->json([ $post ]);


Thanks

13 Dec
5 months ago

murilo left a reply on Set Data In VUE Dinamic

@WILK_RANDALL - I worked , thanks

murilo started a new conversation Set Data In VUE Dinamic

Hello I have a quention , I have a code , That sets diffent datas . is like this ->

if(data.type == "message"){
    this.message = data.result; 
}

if(data.type == "info"){
    this.info = data.result; 
}

if(data.type == "post"){
    this.post = data.result; 
}

How could I make this code dinamic, something like this -

    this[data.type] = data.result; 



Thanks

murilo left a reply on Enable And Desable Appends In A Laravel Search

@LOSTDREAMER_NL - I am using Laravel 5.6 , and it is not working this ->

$result->append('is_liked');

or

$result->append('is_liked')->get();


or

$result->append('is_liked')->all();

murilo left a reply on Enable And Desable Appends In A Laravel Search

@CRONIX - Thanks CRONIX , I tryed to make my search using append like this ->

$result->append('is_liked');

But , didnt worked -

Method Illuminate\Database\Eloquent\Collection::append does not exist.

murilo started a new conversation Enable And Desable Appends In A Laravel Search

Hello , I just discovered working with appends in my Model . I have been working with Vue js , and I have been working to mutch with Json request searches . In some cases I have to use Appends in my model to get some results in my search , like this -

CONTROLLER ->

 $result  = Post::select(['id', 'title' , 'description'])->get()

  return response()->json($result) .

MODEL ->


class POST extends Model
{
    protected $appends = ['is_liked'];

public function getIsLikedAttribute() 
    {
        return $this->likes->where('user_id', auth()->id())->count() > 0;
    }

    }

THE RESULT WILL BE LIKE THIS ->

[{ "id":1 , "title":title , "description":post_description ,"likes":true , .... } ,
  { "id":2 , "title":other title , "description":other post_description ,"likes":false , .... }]

How could I desable appends in my search ? or just use this when I want ?

12 Dec
5 months ago

murilo left a reply on Select Query Posts With Likes

@LOSTDREAMER_NL - Thanks my frined , now it worked .

murilo left a reply on Select Query Posts With Likes

Thanks , @lostdreamer_nl , It shows like that - I can do like this ->


 // WITH LIKES
            ->with([ 'likes' => function($query) {
                
                         $query->where('user_id', '=', $this->user->id);
                 
            } ])


It shows like that ->

[{ "id":1 , "title":title , "description":post_description ,"likes":[{"post_id":44,"user_id":22}] , .... } ,
  { "id":2 , "title":other title , "description":other post_description ,"likes":[] , .... }]

can I make something to shows TRUE or FALSE instead ? like this -

[{ "id":1 , "title":title , "description":post_description ,"likes":true , .... } ,
  { "id":2 , "title":other title , "description":other post_description ,"likes":false , .... }]

11 Dec
5 months ago

murilo left a reply on Select Query Posts With Likes

Thanks very mutch for the help @lostdreamer_nl and @drfraker , in both examples it uses that -

foreach($posts as $post) {
    echo $post->id ." = ". $post->is_liked ."\r\n";
}

But I am using JSON REQUEST , I am not displaying on the VIEW , so I need to bring all those results like this in my CONTROLLER ->


 $result  = Prop::select(['id', 'title' , 'description'])

    // LIKED , IT SAYS TRUE OR FALSE
            ->with([ 'Like' => function($query) { 
                       
            } ])->get()

  return response()->json($result) .

murilo started a new conversation Select Query Posts With Likes

Hello , I have a question , I am developing a website like a facebook . It will have POSTS and a User can LIKE those posts ,

So a user can search all those posts , if this post is LIKED ( this user has given a like ) , so it has to show that this post is liked .

The like and POST is related by Many to MAny relation ship .

Will be like that -

POST MODEL

 // LIKE
    public function Like() {
        return $this->belongsToMany(User::class , 'user_post_likeble' , 'post_id'  , 'user_id');
    }


POST QUERY RESULT ->


  $result  = Prop::select(['id', 'title' , 'description'])

    // LIKED , IT SAYS TRUE OR FALSE
            ->with([ 'Like' => function($query) {
                // I dont know how could I make the relation ship here to say TRUE for those one that has relation chip / FALSE for those one that dont has relation ship .                 

            } ])->get()



Thanks .

murilo started a new conversation ACL In Laravel , Auth

Hello , I am trying to make a ACL auth in Laravel like this tutorial - https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/13

It is working , I have all my users in the same table ( USERS table ) and its use the same guard , they are divided by roles , like this -

ADMIN - $user->hasRole('admin') CLIENTS - $user->hasRole('client') ....

In the login auth / verification , I have to make like this ->

//  search the user 
  $user =  User::where('email' , $request['email'] )->first();

// if has user and the user is admin 
if(! $user || ! $user->hasRole('admin')  ) {

// start making credentials
 $credentials = ['email' => $request['email'], 'password' => $request['password']];

    // verify again
        if(auth()->guard()->attempt($credentials)){

          return true;

        }


Does have any better way to do that ? something like this ->



// start making credentials
 $credentials = ['email' => $request['email'], 'password' => $request['password']];

    // verify again
        if(auth('admin')->guard()->attempt($credentials)){

          return true;

        }

02 Dec
5 months ago
26 Nov
5 months ago

murilo left a reply on Verify Password Is The Same , And Update It .

Hello @kiruba , @zymawy , @BezhanSalleh , I can see that is using Hash:: Instead the bcript() . To incript my password , do I use Hash:: instead bcript as well ? is that more , or less secure than bcript() ?

25 Nov
5 months ago

murilo started a new conversation Verify Password Is The Same , And Update It .

Hy , I am trying to update the password of the user . But before update , the user must type the same password , like this -

  1. verify if the current password is the same .
  2. update the password . ( new one )

I am making like this ->

 if( $this->password !=  bcrypt($request['password'])){
            return true;
        }


But It is not working like this with bcrypt() .

Does some one knows how could I do it ?

Thanks

01 Nov
6 months ago

murilo left a reply on I Cant Understand Fluent Interfaces

@jlrdw , do you think that is posible to make static like this ->

$foo = Foo::setThing('thing')->setOtherThing('other_thing')->save();

How could I make here -


 public  static function setThing($thing)
    {

        $this->thing= $thing;
        return $self;

    }

Thanks

31 Oct
6 months ago

murilo left a reply on I Cant Understand Fluent Interfaces

I discovered how to make this ->

    $foo = new Foo();
       return  $foo->setThing('thing')->setOtherThing('other_thing')->save();

the class will be like this ->


class Foo
{
    protected $thing;
    protected $other_thing;

    public  function setThing($thing)
    {

        $this->thing= $thing;
        return $this;

    }

   public  function setOtherThing($other_thing)
    {

        $this->other_thing= $other_thing;
        return $this;

    }


    public  function save()
    {

            return this->thing  ." and ". $this->other_thing . "are saved";
    }

}

Ok it is working , but how could I make this class static ?

Instead this -

    $foo = new Foo();
       return  $foo->setThing('thing')->setOtherThing('other_thing')->save();

Make something like this ->

    $foo = Foo::setThing('thing')->setOtherThing('other_thing')->save();

is that possible ?

30 Oct
6 months ago

murilo started a new conversation I Cant Understand Fluent Interfaces

I saw this tutorial using Fluent Interfaces , it is very good and practical to organize codes - https://laracasts.com/series/whip-monstrous-code-into-shape/episodes/14

But I could not understand how fluent interfaces works .

Does some one can help me please ?

I wold like to do something like this ->

Foo::create()->setThing('thing');

03 Oct
7 months ago

murilo started a new conversation Static Method For Store , How Use Request / Consider Use Cases

I saw this tutorial -

https://laracasts.com/series/whip-monstrous-code-into-shape/episodes/2

That is amazing , it shows how to clean up the controller code .

The controller wold be like this -

      public function store(){
                
            $podcast = PurchasePodCast::perform(); 
            return $podcast; 
        
    }

My Question is , If I have to add -

  • request
  • user

Wold be a good approache , to make static like this in the same way ?

      public function store(Request $request){
            $user = $this->user;    
            $podcast = PurchasePodCast::perform(request , $user ); 
            return $podcast; 
        
    }

Thanks

04 Aug
9 months ago

murilo started a new conversation USE WhereHas In Poliporph

Hello , I am using a Polimorph relation ship , and and tying to make a Query with wherehas , but I cant . I am trying like that -

MODEL

GALLERY MODEL

  public function importable()
    {
        return $this->morphTo();
    }

QUERY

    // SET QUERIES
        $result  = Gallery::select(['id' ,'importable_id' , 'importable_type' , 'url',  'created_at'])

    
            ->when($table_relation_id , function ($query) use ($table_relation_id) {
               
                 $q->whereHas('importable', function ($q) use ($table_relation_id) {
                          return $q->where('id', $table_relation_id);
                   });
           
            })
    ->get()

Does some one had the same problem ?

27 Jul
9 months ago

murilo left a reply on Accessor | Can We Set Using Other Eloquent Model

you could use get Attribute .

In Model -

POST MODEL 

public function state()
{
    return $this->relationship('App\State');
}

public function getstateNameAttribute()
{
    $this->state->name;
}

In View -

{{ $post->stateName}}

24 Jul
9 months ago

murilo left a reply on GETTING Query Values From Constructor

What I am trying to say @Snapey , is that you cant use $this->name , inside the property like this -

 ... function($q) use ($this->name) {

}

It will give errors . You do need to use variables like this -

$name = $this->name;
 ... function($q) use ($name) {

}

I wold like to know If has some why that I can make in the first option that I showed above .

murilo left a reply on GETTING Query Values From Constructor

hello @Cronix , I am trying to access those values of the controller , but I have to make variables first , I wold like to pass those values direct , like this -

 public function __construct(Request $request)
    {
        $this->name                   = 'John';
     $this->zip_code             = '435345';
        $this->phone_number = '99232321';
    }
   public function getValue() 
  {
       $user = User::::select(['id', 'name')
    ->when($this->name , function ($query) use ($this->name ) {

      })
     ->when($this->zip_code , function ($query) use ($this->zip_code ) {
             ...
       })
     ->when($this->phone_number , function ($query) use ( $this->phone_number) {
             ...
       })

       ->get();
   }

BUT it will gives error HERE - use ($this->zip_code ) , It not aloud me to pass this value from constructor . I have to do like this -

 public function __construct(Request $request)
    {
        $this->name                   = 'John';
     $this->zip_code             = '435345';
        $this->phone_number = '99232321';
    }
   public function getValue() 
  {
    $name = $this->name;
        $zipcode = $this->zip_code;
        $phone_number $this->phone_number;
 
       $user = User::::select(['id', 'name')
    ->when($this->name , function ($query) use ($name ) {

      })
     ->when($this->zip_code , function ($query) use ($zipcode) {
             ...
       })
     ->when($this->phone_number , function ($query) use ( $phone_number) {
             ...
       })

       ->get();
   }

murilo started a new conversation Controctor Method

Hello Guys , I have a question . If I am trying to add the variables of my search directly in the construct , but I dont know if I can put this value directly like this .

it not aloud I add this value like this -

use ($this->name)

LIKE THIS -


    public function __construct(Request $request)
    {

        $this->name = 'John';

    }
   public function getValue() 
  {
       $user = User::whereHas('UserInfo', function($q) use ($this->name) {
            $q->where('name_user', $this->name);
        })->get();
   }

I have to do like this -


    public function __construct(Request $request)
    {

        $this->name = 'John';

    }
   public function getValue() 
  {
    $name = $this->name;
       $user = User::whereHas('UserInfo', function($q) use ($name) {
            $q->where('name_user', $name);
        })->get();
   }

Does some one knows If it has any way to to add this value getting directly from constructor ? something like this -

User::whereHas('UserInfo', function($q) use ($this->name)  { ... 

Thanks

23 Jul
9 months ago

murilo left a reply on Find Queries Where Between First Letters Start With *

could explain better @jlrdw ? do you think that have an easiest way than this ?

User::select(['id', 'names'])
    ->where('names', 'like', "a%")
    ->orWhere('names', 'like', "b%")
    ->orWhere('names', 'like', "c%")
    ->orWhere('names', 'like', "d%")
    ->orderBy('names')
    ->get();

becose imagine if I have to search from A to Z ...

murilo started a new conversation Find Queries Where Between First Letters Start With *

I have a Question , I have a List of names , like this -

Alexander , Callum , Charles , Charlie , Charlie , Connor , Damian , Daniel , David , Ethan , George , Harry , Jack , Jake , James , James , James , Joe , John , Joseph , Kyle , Liam , Mason , Michael , Noah , Oliver , Oscar , Reece , Rhys , Richard , Robert , Thomas , Thomas , William 

and I want to GET all names between Letters -> A to D , need to show me this -

Alexander , Callum , Charles , Charlie , Charlie , Connor , Damian , Daniel , David 

How could I do it ?

something like this ->

     $query = User::select(['id', 'names' ]->where('name' , [ 'a%',  '%d'])   ->latest()->get();

Thanks

20 Jul
9 months ago

murilo started a new conversation MYSQL Big DB Importing Via MySQL Workbench Is Giving Error , Importing In Wrong Orde

Hello , I have a question , I have a BIG database to import via Mysql Work bench . I am using MYSQL 5.7 , I am trying to import my database via workbanch ,but is giving error of raletad ID , it is not importing on right order .

It shoud import first -

  • STATE TABLE
  • CITY TABLE ( with state_id )

but is importing city table before state table, so it is giving error , becose city table has state_id .

I have to import all the columns that comes first ( STATE TABLE ), after import those columns that comes after (CITY TABLE) .

IT is giving me a lot of problem this .Does this happened with some one ? Does some one know what to do ? Thanks

17 Jul
10 months ago

murilo started a new conversation Eloquent Where HAs

Hello , I have a question .

if I do like this , it works -


       $user = User::whereHas('UserInfo', function($q) {
            $q->where('name_user', 'John');
        })->first();

        dd($user);

BUT , I am trying to do this Dynamic , like this -

  $name = "John";
       $user = User::whereHas('UserInfo', function($q , $name) {
            $q->where('name_user', $name);
        })->first();

        dd($user);

It will not work , It will give me errors , does some one knows how could I make Dynamic like the second option ?

07 Jul
10 months ago

murilo left a reply on Error Installing Homestead In MAC

I am using a macOS Hight Sierra 10.13.5

murilo started a new conversation Error Installing Homestead In MAC

Hello Guys , I am trying to install Homestead in MAC , but I am getting Errors when I make the VAGRANT UP . this is the error -


There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Failed to create the host-only adapter
VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
VBoxManage: error: Context: "RTEXITCODE handleCreate(HandlerArg *)" at line 94 of file VBoxManageHostonly.cpp

Does some can help me , please .

Thanks

26 Jun
10 months ago
04 Jun
11 months ago

murilo started a new conversation WhenWhereHas Eloquent

Hello , I have a question .

I want to search Tags ( Many to Many ) in My post , JUST if I select those tags in my search .

I have my code like this -

$tags = $request->input('tags');

Post::select(['id', 'title' , 'description'])
      // TAGS (MANY TO MANY )
            ->WhereHas('Tags' , function($query)  use ($tags ) {
             
                    return $query->where('id' , $tags );
          
            })->latest()->get()

But it dows not have a option if my Tag is empty . I wold like to make something like this -


$tags = $request->input('tags');

Post::select(['id', 'title' , 'description'])
      // TAGS (MANY TO MANY )
            ->IfWhereHas('Tags' , function($query)  use ($tags ) {
             
                    return $query->where('id' , $tags );
          
            })->latest()->get()

  • IfWhereHas or WhenWhereHas , does have this option in Laravel ?
29 May
11 months ago

murilo left a reply on Laravel + VUE Form Request

I tried to make like this -

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

abstract class Request extends FormRequest
{
    protected function validationData()
    {
        $data = $this->all();

        // if is not an array , so json_decode()
        foreach ($data as $key => $form_items) {

            if(! is_array($form_items)){

                $data[$key] = json_decode($form_items);

            }else{
            // HERE IS ARRAYS 

                $list_array = [];
                foreach($form_items as $key_array => $va_array) {
                    $list_array[$key_array] =  $va_array[$key_array];

                }

                $data[$key] = $list_array;

            }

        }

        return $data;

    }
}


It is not working for ARRAYS

murilo started a new conversation Laravel + VUE Form Request

Hello Guys , I am sending data from VUE to Laravel with AXIOS , I am using json_decode() in Laravel to decode the data , I am making the samething in FormRequest , But I am having problem to make the json_decode() in forms with arrays .

I GET All those data I get like this in Laravel ->

$title = json_decode($request['title']);
Instead of 

$title = $request['title'];

Well , It is working fine . But the problem is the form request , it is like this -

return [
            'title' =>  'required',
        ];

    // I can not make , json_decode() inside here .

So I found a class on Internet , that Extend Form Request to send those data from VUE Js .

It is like this -



abstract class Request extends FormRequest
{
    protected function validationData()
    {
        $data = $this->all();

        // if is not an array , so json_decode()
        foreach ($data as $key => $form_items) {

            if(! is_array($form_items)){
        // here is not array , is making json_decode() in filds that is not array , it is working   
                $data[$key] = json_decode($form_items);

            }else{
                // HERE IS ARRAY , I DIDNT MANAGED 
        // I dont know how I could use json_decode() here inside , I used foreach() .... and every thing , but It didnt work , I should make some change here to be able to use json_decode() in arrays .

                $data[$key] = $form_items;
            }

        }

        return $data;

    }
}

It is very hard to explain , I dont know if some one will understand , but thanks if some one help me .

27 Apr
1 year ago

murilo started a new conversation Form Request Validates An Array

Hello Guys , does any one there knows how can I validate and array with form Request ?

I want to make something like that -

   public function rules()
    {
        return [
            'user[id]'               => 'required' ,
            'user[status]'   => 'required' 
        ];
    }

I tried like this as well -

   public function rules()
    {
        return [
            'user.id'               => 'required' ,
            'user.status'       => 'required' 
        ];
    }
23 Apr
1 year ago

murilo started a new conversation Auth Credential

Hello Guys , does some one can help me ? I am making a verification Guard for AdminUsers and CoustomerUsers , like this -

https://laracasts.com/lessons/users-and-roles

I have my table USER -

    id | name | email |password
        1 | John | [email protected] |12345

I have my table USER_ROLE -

    id | name_of_role 
       1  | admin

I have my table USER_ROLE_USER , ( MANY TO MANY RELATION SHIP)

    user_id | role_user_id 
        1 | 1

I changed the file -RedirectIfAuthenticated and Added those guards .

It is working and redirecting how is loged in with roles .

BUT I have to change this credentials that verificate in my Authentication Login on Laravel , it is like this -

  $credentials = ['email' => $request['email'] , 'password' => $request['password'] ;

        if(auth()->guard()->attempt($credentials)){
        ....
    }

I should verificate the role as well in the credentials , something like this -

  $credentials = ['email' => $request['email'] , 'password' => $request['password'] ,  'role' => ?  ;

        if(auth()->guard()->attempt($credentials) ){
        ....
    }

Thanks

murilo left a reply on User And Roles Gate

I have found the mistake , I have to do like this -

$gate->define

Thanks

murilo started a new conversation User And Roles Gate

Hello Guys , I use to make a muth authentication like this -

https://laracasts.com/lessons/users-and-roles

but now in Laravel 5.6 , is not working this type of Authentication , maybe somethis has changed .

In AuthServiceProvider , I have this code -

use Illuminate\Support\Facades\Gate as GateContract;

  public function boot(GateContract $gate)
    {
        $this->registerPolicies();


        foreach ($this->getPermissions() as $permission){

            $gate->define($permission->title , function($user) use ($permission){
                return $user->hasRole($permission->roles);
            });

        }


    }

    protected function getPermissions(){
        return UserPermission::with('roles')->get();
    }

but is giving this error

Class 'App\Providers\Gate' not found

dows some one knows what is happenig ?