Jump to content

Anybody know how to perform MySQL queries in Laravel 5?

Go to solution Solved by keja,

Here is a tut that shows how to build a todo list:

https://www.flynsarmy.com/2015/02/creating-a-basic-todo-application-in-laravel-5-part-1/

 

it does not cover joins but you just do something like this:

DB::table('users')            ->join('contacts', 'users.id', '=', 'contacts.user_id')            ->join('orders', 'users.id', '=', 'orders.user_id')            ->select('users.id', 'contacts.phone', 'orders.price')            ->get();

code also from the like i posted in my first post :)

Hi there,

 

It's been a while since I was on here...

 

So, my team has to build a working site in 72 hours (short time, right?) using Laravel.

 

So far, we have the UI ready (thanks to Materialize) and have no problems with making them...

he main problem is that due to the lack of time, we were not taught how to perform sql queries properly with laravel...

 

the laracasts and documentation aren't helping too much either...

 

pls halp...

 

-Hermit

 

P.S.

To those who wonder why I was off for a really long time, it's because of a lot of stuff going on IRL... Like this one right here...

Link to comment
Share on other sites

Link to post
Share on other sites

Take a look at the documentation :)

 

http://laravel.com/docs/5.0/queries

 

 

Basic CRUD:

//INSERT INTO users SET email='john@[member=Example].com', vote=0DB::table('users')->insert(['email' => 'john@[member=Example].com', 'votes' => 0]); 
//SELECT name, email FROM users$users = DB::table('users')->select('name', 'email')->get();
//UPDATE users SET votes=1 WHERE id=1DB::table('users')->where('id', 1)->update(['votes' => 1]);
//DELETE FROM users WHERE vote = 1DB::table('users')->where('votes', '=', 1)->delete();
Link to comment
Share on other sites

Link to post
Share on other sites

 

-magicsnip-

 

Yeah... Thanks...

Looked at documentation already....

I'm still having some trouble figuring out how things will go from here...

 

So far, I need to build a module that does basic crud but does it with multiple tables simultaneously...

 

another thing that i have no idea on doing is how to get input data from forms and pass to the method...

Link to comment
Share on other sites

Link to post
Share on other sites

Here is a tut that shows how to build a todo list:

https://www.flynsarmy.com/2015/02/creating-a-basic-todo-application-in-laravel-5-part-1/

 

it does not cover joins but you just do something like this:

DB::table('users')            ->join('contacts', 'users.id', '=', 'contacts.user_id')            ->join('orders', 'users.id', '=', 'orders.user_id')            ->select('users.id', 'contacts.phone', 'orders.price')            ->get();

code also from the like i posted in my first post :)

Link to comment
Share on other sites

Link to post
Share on other sites

Here is a tut that shows how to build a todo list:

https://www.flynsarmy.com/2015/02/creating-a-basic-todo-application-in-laravel-5-part-1/

 

it does not cover joins but you just do something like this:

DB::table('users')            ->join('contacts', 'users.id', '=', 'contacts.user_id')            ->join('orders', 'users.id', '=', 'orders.user_id')            ->select('users.id', 'contacts.phone', 'orders.price')            ->get();

code also from the like i posted in my first post :)

 

Thanks... You just led me to exactly what I was looking for... (code in context)...

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×