danielesposito

J. Web Developer at Gia Consulting

Experience

15,420

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 147 Lessons Completed
  • 2 Favorites

22nd February, 2018

danielesposito left a reply on Get Relational Data Of Many To Many Relationship With Multiple Database Connection • 3 months ago

@lostdreamer_nl

Unfortunately is not working, I'm still getting the same error.

Illuminate\Database\QueryException with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: the "task_user" relationship does not exist

danielesposito left a reply on Get Relational Data Of Many To Many Relationship With Multiple Database Connection • 3 months ago

@lostdreamer_nl

I've done everything you said but I'm getting this error:

ErrorException with message 'Declaration of App\Task::newPivot(Illuminate\Database\Eloquent\Model $parent, array $attributes, $table, $exists) should be compatible with Illuminate\Database\Eloquent\Model::newPivot(Illuminate\Database\Eloquent\Model $parent, array $attributes, $table, $exists, $using = NULL)'

danielesposito left a reply on Get Relational Data Of Many To Many Relationship With Multiple Database Connection • 3 months ago

@lostdreamer_nl

Hey, Thank you very much for your support!!

After setting this stuff how should a call the relationship?

class Task extends Model
{
    protected $connection = 'host2';

    public function users()
    {
        return $this->belongsToMany(User::class, 'task_users', 'task_id', 'user_id');
    }
}

Will I have to leave like that?

danielesposito left a reply on Get Relational Data Of Many To Many Relationship With Multiple Database Connection • 3 months ago

@lostdreamer_nl

Hi there, thanks for reply

Could you be more explicit about where I have to place this files and where should I call in my models? I'm pretty new to laravel and I'm a bit confused.

Thanks

danielesposito started a new conversation Get Relational Data Of Many To Many Relationship With Multiple Database Connection • 3 months ago

  • Laravel Version: 5.5.
  • PHP Version: ">=7.0.0",
  • Database Driver & Version: MySQL

Description:

I'm working with multiple database connections that have different schema. host1 and host2. My default database connection is host2. My project has two tables. users exist on host1 and tasks exists on host2.

There is a many to many relationships on both tables. Pivot table for this relationship is task_users which exist on host2.

My model files are here.

User.php

class User extends Authenticatable
{

    protected $connection = 'host1';

    public function tasks()
    {
        return $this->belongsToMany(Task::class, 'task_users', 'user_id', 'task_id');
    }
}

Task.php

class Task extends Model
{
    protected $connection = 'host2';

    public function users()
    {
        return $this->belongsToMany(User::class, 'task_users', 'task_id', 'user_id');
    }
}

Steps To Reproduce:

Here is what I'm trying to do

$task = Task::find($taskId);
$task->users;

With this model files, when I'm trying to get users of a task, I'm getting this error.

Illuminate\Database\QueryException with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: the "task_user" relationship does not exist

But then if I do the inverse like this:

$user = User::find($taskId);
$user->task;

everything goes fine.

I have almost spent too much time to resolve this. But didn't get anyway. I don't know either this is an issue in laravel, not supported or I'm doing in wrong way.

Any Help out there? I will really appreciate any suggestions on how to solve this.

20th December, 2017

danielesposito left a reply on Attach Method • 6 months ago

Hello, @tykus thanks for your reply,

As the documentation show:

If you do not want to detach existing IDs, you may use the syncWithoutDetaching method: $user->roles()->syncWithoutDetaching([1, 2, 3]);

And following this, I have successfully got returned the id of the items I was attaching for, so, this means I can't get the entire object back, how should go for this? Need to make another call on DB?

D

danielesposito started a new conversation Attach Method • 6 months ago

###Hello to everyone.

I would like to understand why the "attach" method returns null when successfully inserted and so how can I check that was successfully inserted?

Many thanks

D

5th December, 2017

danielesposito left a reply on Pivot Tables And Eloquent. • 6 months ago

Hello, @Dunsti and @burlresearch thank you for your reply.

I have just solved it doing this:

class Games extends Model { public function players() { return $this->belongsToMany(Players::class, Games_players, id_game, id_player)->withPivot('id_role') ->join('Role_Players', 'Games_players.role_id', 'Role_Players.id_role') ->select('bda_soggetti.*', 'bda_ruolo_sog.descrizione AS descrizione_ruolo'); } }

It is working well, but is not what I was looking for. I have read the thread you mentioned above and I will give it a try, it seems interesting.

As I understood from your thread, have to create a model on the pivot table like this:

use Illuminate\Database\Eloquent\Relations\Pivot;

class GamePlayer extends Pivot { public function role() { return $this->belongsTo(Role::class); } }

and then map the role on the pivot table like:

class Role extends Model { public function game_player() { return $this->hasMany('App\GamePlayer'); } }

So by this way, I may access to the role related to the player on the games doing $game->players->pivot->role->description.

Correct me if I miss something, please.

Anyway, I will let you know if it's working.

Many thanks again for the support. Love this community behind the world of laravel on Laracasts.

@JeffreyWay Big Thanks.

4th December, 2017

danielesposito started a new conversation Pivot Tables And Eloquent. • 6 months ago

Hello to everyone, this is maybe the hardest problem I'm facing since I use laravel and I hope some of you might help me to solve it.

So, I have the following schema in my database:

| Games | Players | Role_Players | Games_players | +--------------+----------- + ---------------- +----------------------- | id_game | id_player | id_role | role_id | | | | description | game_id | | | | | player_id |

Now, I have a many to many relationships with games and players and the following model

Class Games extends Model {

public function players {

    return $this->belongsToMany(Players::class, Games_players,  id_game, id_player)     


}

}

This will return all the players associated with games, but how can I return the role of the players in this game? I know that I have an object $games->players->pivot where I can add the column role_id, but how can I get for example the description using eloquent? I'm struggling to get this work.

I will appreciate any help.

Thanks.

D

danielesposito left a reply on Help Needed • 6 months ago

@Snapey ,

I have followed your advice. In the page, I hide the results, and when the users require seeing the results throw the button I show a section on the same page where they can read the results.

1st December, 2017

danielesposito left a reply on Help Needed • 6 months ago

Hello @Snapey,

You right, maybe I wasn't clear about it, I will try to explain better.

  1. The user came to the page where I have a form to search a resource on site.

  2. The user makes the request, (I process this request with Ajax).

  3. I make a query in the controller then, send back to the user without showing the result.

  4. If the request has results I show a button, informing the user that the search has, for example, 3 records.

  5. If the user wants to see the results, all he needs to do is to click the button and go to the page where I need to show him the results.

Now, in step 3 I have already the data, my need is to bring this data on another page, so it's like to send data view to view. I have tried with ajax but it is not possible as you now that I can't redirect from the controller when I process the request, and even with a classic post request I'm able to send the object to the controller.

Maybe I'm doing wrong, hope that is clear enough to give me some help.

Many Thanks

D

30th November, 2017

danielesposito left a reply on Help Needed • 6 months ago

@miiikkeyyyy Hello,

thanks for the reply.

How I send it to the controller??

danielesposito left a reply on Help Needed • 6 months ago

@wilk_randall Hello,

Yes, I know that is possible do that, but instead of a collection of input that I send to the controller, like doing a registration form, I have already in my view the object I need to send. The object I got looks like this:

resultSearch:

Array[2] {

0: {
    civico:"1"
    denominazione:"Entita"
    id_comune:null
    id_entita_terr:1
    id_tipo_entita:1
    indirizzo:"via xxxx"
    targa:"xxx"     
},
1: {
    civico:"1"
    denominazione:"Entita"
    id_comune:null
    id_entita_terr:1
    id_tipo_entita:1
    indirizzo:"via xxxx"
    targa:"xxx"     
},

}

That's what I should send to the controller that I already have in my view.

danielesposito left a reply on Help Needed • 6 months ago

Hello @wilk_randall, @ejdelmonico

Thanks for your reply,

I thought that solution as well, but how can I send a collection of objects using a normal post request? Then, when I got the post request in the controller should I redirect the user with a flash session containing the object? I was trying to send throw it with ajax, but of course, it comes back on the same page and I have to send this data to another view.

29th November, 2017

danielesposito started a new conversation Help Needed • 6 months ago

Hello to everyone,

I need to pass an object from a view to another view, and I really can't get it.

The scenario is this:

  1. I send a post request to a controller with ajax and, get the results and I store it in a variable without changing page.

  2. Now I have a button that needs to redirect me to another page with the data I got in the previous ajax call.

Can please some of you help me out?

I will appreciate any suggestions.

Thanks

D

22nd November, 2017

danielesposito started a new conversation Best Practices, Search With Laravel And Vue • 6 months ago

Hello to everyone and hello @JeffreyWay

I have got a doubt and I believe some of you may help me. I'm on a project and I need to build a search component. This search will have some filter on the resources that users are searching on and one of this will be a select list of categories.

How should I expose this list to Vue? Which are the best practices? I have to create a dedicated controller where I fetch the data needed and call it with Ajax? Better to create an API Resource and call it from a route? Should I use the API routes?

As most of you, I'm using laravel as backend and Vue for the front-end. I hope some of you can help me out to better understand this concept.

I will appreciate.

Thanks

D

13th October, 2017

danielesposito left a reply on View Not Found • 8 months ago

@36864

The other routes I have created are protected by the make: auth command. What I have done is that I created a new route and a new view called home and still not working. I did a fresh installation of laravel and everything worked even from outside. I tried to change the port of my server to:82 and still not working. But now like a magic when I came back to the initial setting, everything working fine, but I can't you guys explain how. How can I activate debugbar? maybe can be helpful next time.

Really thanks for the help!

danielesposito left a reply on View Not Found • 8 months ago

@36864 Hello there,

Yes, I'm sure that my server is running and it's well configured as I got another project there with vue and is everything fine.

I just wrote all the command you suggesting but still get not working.

I removed the root route from web.php and when I tried to access it by typing from the other pc ( no from the VM ) I got the same issue, "sorry, page not found", then added again and getting back just the route.

This is struggling me because I can't really understand why if I try from local is working.

Thanks anyway

D

danielesposito left a reply on View Not Found • 8 months ago

@ChristophHarms,

I have tried what you said, with no success. I changed the "APP_URL" under .env file but still not working. You how can I check the generated URL of the app?

Those are the step I did:

  1. composer install
  2. php artisan migrate
  3. php artisan cache:clean
  4. npm install

danielesposito left a reply on View Not Found • 8 months ago

@ChristophHarms

And after that I should run php artisan clean:cache and other command ?? I will try and I will let you know.

Thanks

danielesposito left a reply on View Not Found • 8 months ago

@Snapey hello,

Yes I did it all! But still not working.

danielesposito left a reply on View Not Found • 8 months ago

@ChristophHarms Hello,

As you said in the post I cannot access to the VM from the outside world, but as I said in the post I can access to the welcome view. So if it is like you mentioned I couldn't access even to the welcome view isn't it ? Anyway I will check it out ! Thanks for reply.

D

danielesposito started a new conversation View Not Found • 8 months ago

Hello to everyone, I really need help.

I have a laravel project and I moved the whole project from my local machine to a virtual machine and now I'm struggling with several problems. If I log into my virtual machine and try to access via browser with localhost my site runs ok. But if a try on a different computer on the same LAN to access the site I can see only the welcome page, the other one doesn't work, it shows me, sorry, page not found. I even tried to create other views from scratch on VM and getting the same error.

I will really appreciate any suggestions from you guys. I really need to resolve!

Thanks to you all.

18th September, 2017

danielesposito left a reply on Vue And Google Maps • 9 months ago

Hi @topvillas,

Thanks for your reply. I have already seen that on githubs, but I think it is too much for my need. All I have to do is to handle one or two events from the maps. My big problem is to share data and events between them and keep updating them sync.

danielesposito started a new conversation Vue And Google Maps • 9 months ago

Hello to everyone, I'm pretty new to vue js and I will appreciate all kind of suggestions. I'm taking part of a new project and we are planning to use vue js as a front end. I need to integrate google maps with vue and I don't know where to start. I need to build a dashboard with google maps and I have to handle a few events from there, like right click on the maps, add markers and so on. Let's take an example: on the right, I will have a few tables that show up some data, like persons, vehicle. Then on the left, I will have the maps and I need to show all data took from the tables as markers. In other words, I will have to share the data with maps. Then I need to handle events, for example: when I right click on the maps I need to launch a modal that shows a form, with that form I can add persons or vehicle on the maps and in the same time I need to update the tables on the right. Now, my questions are: how can I share the data between the maps and the tables? How can I handle the events from the map, add markers and update the tables as well? Which is the best way to create a component for the map?

Thanks to everyone the will help me to rich my objective.

D.

4th September, 2017

15th April, 2017

danielesposito left a reply on I Would Like To Know Your Opinion • 1 year ago

Hey @FourStacks

Thank you for your time!! I really appreciate that, as you were on the some position I'm now, you can understand how is important to have someone who can help you with it and this discussion is helpful for me!! I got a really project on my mind and I will do it!! I'm stick on laracasts right now getting better on php, restful ecc. My only problem is that I'm not just a freelance and got less time to learn and tuned all the time! But I won't give on this and ready to work hard !! Anyway your advice makes lot of sense to me thanks !

13th April, 2017

danielesposito left a reply on I Would Like To Know Your Opinion • 1 year ago

@endian I think I do start with lumen as you say it more flexible to move the project into Laravel. Obv before I need to better understand OOP and follow some others series of Jeffry.

Thanks. D.

danielesposito left a reply on I Would Like To Know Your Opinion • 1 year ago

@endian

Thank you man, your answers were helpful !! I appreciate that !! You right should know what you need to build your app, and then choose a framework that can help you with it. Using a framework like Laravel yielding just the 5% of the power it has, it could be unnecessary. So, I wanna start to build a website with a few pages and some call to the database as a start point, what you suggest? Lumen or Slim?

danielesposito left a reply on I Would Like To Know Your Opinion • 1 year ago

Hello @endian, what is that about? what do you mean for micro-framework? It allows you to build up a site? Do you suggest me that because is more flexible to understand? Anyway thanks, i gonna take a look to it.

D

12th April, 2017

danielesposito left a reply on I Would Like To Know Your Opinion • 1 year ago

@gustav1105 thanks a lot for your clear answers. As a self-taught developer like you, sometimes I get confused on which is the best way to follow. I will keep the official documentation close to me and will never let it go.

danielesposito left a reply on I Would Like To Know Your Opinion • 1 year ago

Hello @endian, Yeah that's what I would do. I got a project in my mind I believe it's hard to achieve, that's why I started watching the series. I think before to start I need to know at least the basics, then I will move to the project, and it would be great to get support from you'll.

Thanks anyway.

danielesposito left a reply on I Would Like To Know Your Opinion • 1 year ago

Hello @bastman69,

Thanks, I will advantage from your suggestion.

danielesposito left a reply on I Would Like To Know Your Opinion • 1 year ago

Hi, @gustav1105 thanks for your reply. Yes, I'm using mac environment and I really love it. Once I finish the course that I'm following, I will provide to install homestead on my mac as you suggested above.

What about the Laravel course? Do You think I can start from the series Laravel 5.4 from scratch or I have to watch the previous series?

Thanks by the way. D.

danielesposito started a new conversation I Would Like To Know Your Opinion • 1 year ago

Hello to everyone, First of all, my name is Daniele and I'm a junior web developer of PHP. I have good knowledge of procedural code, but I wanna go on. I know a bit of OOP, this means I know what a class is, how to extends it and how to manage methods. I love the idea to learn Laravel, composer and so start to follow all PSR standards, Git and Github, Server management with forge, I wanna even start to use PHPUnit to test out my code and all the stuff the comes after that to get a good level as a web developer. Now, my question is: where should I start? I have started a few days ago, The PHP Practitioner series. What should be my next step? What should be my plan to learn all about it? I will appreciate all kinds of advice from your experience. Many Thanks to y'all. D.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.