Pumps – My Most Valuable Tips

Where to Find the Best Male Reproductive Organ Enlargers

There are a lot of products that are labeled for male reproductive organ enlarger. With these male reproductive organ enlarger products, the main purpose is to help the man get a bigger and better erection for intercourse. The male reproductive organ is super effective and in a short amount of time, it became viral and popular. Before you even try to use the male reproductive organ pump, make sure that you learn the effects and the benefits of the product first. This has made a lot of men interested about the male reproductive organ pump and what it can do to their male reproductive organ.

Pumping means that you are applying vacuum to the body part. The male reproductive organ pump has about two parts.

You have the pump first.
The second part will be the cylinder.
You will be needing a lubricant and constriction band other than the pump and cylinder. But these things usually come with the male reproductive organ pump kit.

When using the male reproductive organ pump, you can have it manually or you can have it electrically driven. The tube that you use will take in air and will pump only the male reproductive organ.

There are different aspects on how the cylinder will produce the after effect. The parts will be the base, the cylinder’s wall and the top and diameter of the cylinder. You will have to get the lubricant ready after having the other parts already, the lube will then be applied to both male reproductive organ and base of the cylinder. You need lubricant to ease your male reproductive organ into the cylinder. The male reproductive organ will have an easier stretching time and the seal will be tighter as well.

You will surely have fun with male reproductive organ pump, this is the type of product that will give your male reproductive organ all the qualities it needs.

The cylindrical tube is one of the most important part of the pump. When you get a small cylindrical tube and your thing will not fit, there is only one thing left to do. The only thing you can do if you get into the situation is to replace the pump.

For a successful outcome, you should really think about considering the guide above and follow the most essential step for all and that is research, for the best rent to own home, you will have to look for that and with the internet’s help, you can!

This will be the best guide to follow to finally get the size that you want to have for the intercourse, this is the quickest way to your happiness.

aboard united parcel service and goblet professionals really get the job done each and every time i need these phones board up a building or my company.

Preparing repairs and improvements in an office which will continuously be working with the course of action could actually be a difficulty simply because one, accidents may happen, and two, it’s going to be really a lot unproductive for the workers and can lead to ineffectiveness. With this particular issues determined, the most effective option you can produce is to have a board up.

As the operator, you can choose as to conduct maintenance and enhancements throughout business hrs or after. Again, let me reiterate, there is the tendency that if you choose to employ it during enough time the workers work they won’t be able to deliver top quality final results because of being diverted, or could not create their standard number of components for a evening than that of what they are accustomed to. Now, if you will choose to allow them to function right after office hours then they’ve got to carry out a chicago board up services to prevent injuries from occurring when they’re not around.

Nevertheless, its not all companies have the protection to be effective throughout the night which is why we at Table Up And Goblet Professionals delivers our services twenty-four hours a day to cater to most of these scenario. We promise to provide you with the best end result and also to give our entire emphasis and when operating even when we’re not searching. We are going to also be sure to provide a powerful industrial aboard in Barrington so that even when all of us is just not inside the locality, the safety of you and your employees it’s still made sure. Contact our consumer representatives now to inquire about our quotes along with the level individuals companies. You might also check us out at our head office in order to have your deals get dealt with faster.

A Simple Plan: Services

3 Benefits to Massage Therapies

There are some people who do not like being massaged at all, while there are other people who enjoy it very much; the truth is, massage therapies are actually very beneficial to people. It does not matter how old you are, you will definitely be in need of a massage therapy, especially if you are going through acute and chronic conditions, backaches, injury rehabilitation, illnesses, disability, etc. There are really a lot of benefits that massage therapies can give people; if only these people will give it a try they will really see that it does work and they will leave the massage therapy for the better because of all the benefits it gives them. There are really super many benefits to massaging; however, here are 3 of the most common benefits that you can receive from massage therapies.

The first benefit to massage therapies is that it counteracts all that sitting people do; most people sit down throughout the day and this can actually be harmful to their health, but with massage therapies people’s bad posture while sitting can be fixed. People that sit down too much and do not schedule themselves to a regular massage therapy will surely experience lower back pains, shoulder pains, and neck pains; that is not a pleasant feeling when these parts are in pain. The reason why massaging is good for a person who sits down a lot is because it can actually counteract the imbalances that sitting can cause in the body.

You will be happy to know that massage therapies do not only just cure the pains from sitting down too much, but they also cure any muscle pain that you might have; and this is actually very beneficial to you. Muscle pains, whether it is from an injury or bad posture or just a sore muscle, will get worst and worst if the person does not try to cure it, and that can lead to severe pain. A reason why massage therapies can cure muscles aches is because when there is applied pressure to an aching muscle, the blood circulation increases and improves, and with increased and improved blood circulation, the pain can very well go away.
Why People Think Massages Are A Good Idea

A person who is experiences any level of anxiety or depression can really benefit from massage therapies because that is the third benefit, that they can sooth anxiety and depression in a person. Anxiety and depression are actually two factors that can really cause harm to a person, physically and mentally; a person who is experiencing these should really do something to remove it before it gets any worst. If you want to soothe your anxiety and depression away, then you should really go to a massage therapy because it will make you feel very relaxed and take your mind off your problems.What Research About Services Can Teach You

Professionals – Getting Started & Next Steps

Rights of an Employee in Workers’ Compensation Law

To start with, this is an insurance that covers the workers who get injured or fall sick during work. This law clearly outlines the duties and responsibilities of a worker. Other than that, it covers the employer’s obligations to his employee. Various conditions may expose workers to ailments. They only need to claim for compensation. But before everything, they have to make sure that they follow the speculated guidelines in the workers’ compensation law. Various states have different rules that guide any employee at work.

This law covers all the injuries incurred while working in any firm. For example, an industry involved in manufacturing soap for consumers. In the process, if poisonous chemicals leaked and harmed the worker, he/she has a right to claim for compensation. Other activities such as lifting heavy stones or loads may expose a worker to injuries. In such a case, they may break parts of their body. Apart from breaking limbs, they may also break their backs. The worker is obligated to demand compensation.

Other injuries may occur when a worker is exposed to too much typing. They may hurt their backs, this is a result of too much bending. In such an instance, they are supposed to claim for compensation. Sometimes workers get injured while outside work locations. An example is when a worker is involved in an accident while attending to duties in far places.
What Do You Know About Attorneys

Workers may also get burned in the process of working. This normally happens when a heating device has a defect. A fire incidence is likely to occur. The employer should fulfill the rights of his employee by compensating him/her.

There’s quite a number of benefits accrued from workers’ compensation law. They are as follows. The medical expenses are paid for. High quality and immediate care pertaining the hospital should be sorted out by your employer. Other than getting you a van to the hospital, they should also cater for all medical expenses.
If You Think You Understand Attorneys, Then Read This

Other benefits are related to time off wages. The period when workers are sick and are recuperating do not favor them to work. This means that they are not productive in their specific fields. Although, at the end of the month, they are still supposed to earn the salary. The salary must also include the time they were on sick leave.

Long term impairments such as broken limbs and loss of eyesight may be brought by other injuries. The workers compensation law should ensure that workers are granted such long-term compensation. All the expenses incurred from the time of the injury to the time of full recovery should be catered for. Note that other injuries are permanent.

An employee may also get re-training benefits. Perhaps the worker got injured because they used wrong procedures to complete a task. For instance, wrong use of ingredients during soap making. The employers may choose to offer training classes to their workers to avoid future injuries.

Mastering Laravel

Mastering Laravel

Mastering Laravel by Christopher John Pecoraro

PHP, a free and open source programming language, is continuing renaissance and Laravel is at the forefront. Laravel 5 is proving to be the most usable framework for novice and expert programmers alike. Following modern PHP’s object-oriented best practices, reduce the time to market and build robust web and API-driven mobile applications that can be automatically tested and deployed.
You will learn how to rapidly develop software applications using the Laravel 5 PHP framework.
What this book covers
Chapter 1, Designing Done Right with phpspec, speaks about how to configure Laravel 5 for phpspec to perform modern unit testing, to use phpspec to design classes, and to perform unit and functional testing.
Chapter 2, Automating Tests – Migrating and Seeding Your Database, covers database migrations, the mechanics behind them and how to create a seed for testing.
Chapter 3, Building Services, Commands, and Events, talks about Model-View-Controller
and how has evolved into services, commands, and events to decouple code and practice separation of concerns.
Chapter 4, Creating RESTful APIs, takes you through the creation of a RESTful API: the basic CRUD operations (create, read, update, and delete), as well as discussing some best practices and hypermedia controls (HATEOAS).
Chapter 5, Using the Form Builder, takes you to the web interface side of things and shows you how to take advantage of the some of the newest features of Laravel 5 to create web forms. Reversed routing will be discussed here as well.
Chapter 6, Taming Complexity with Annotations, focuses on annotations. The routes. php file easily becomes messy when an application grows in complexity. Using annotations inside of controllers, code legibility is drastically increased; however, there are some disadvantages in addition to the advantages.
Chapter 7, Filtering Requests with Middleware, shows you how to create reusable filters that can be called either before or after the controllers.
Chapter 8, Querying the Database with the Eloquent ORM, helps you learn how to use an ORM in a way to reduce the probability of errors in coding, increase the security and reduction of SQL-injection probability, and also learn how to deal with the limits of the Eloquent ORM.
Chapter 9, Scaling Laravel, speaks about scaling an application to move it into a cloudbased architecture. The read/write master/slave configuration is discussed and the reader is guided through the configuration.
Chapter 10, Building, Compiling, and Testing with Elixir, introduces Elixir. Elixir is based on gulp, which is a task runner and is a series of build scripts that automates common tasks in the Laravel software development workflow.
What you need for this book
We’ll need the following software:
• Apache/Nginx
• PHP 5.4 or greater
• MySQL or similar
• Composer
• phpspec
• Node.js
• npm
Who this book is for
If you are an experienced novice or a capable PHP programmer who has a basic understanding of the concepts of modern PHP (at least version 5.4), then this book is ideal for you.

Create a CRUD Application with Laravel 5.2 (Part-6)

Editing user information

Now as we learned how easy it is to add and list users. Let’s jump into editing a user. In our list users view we have the edit link with the following code:

{{ link_to_route('users.edit', 'Edit', array($user->id), array('class' => 'btn btn-info')) }}

Here, the link_to_route function will generate a link /users/<id>/edit, which will call the resourceful Controller user, and Controller will bind it with the edit method.

So here is the code for editing a user. First of all we are handling the edit request by adding the following code to our UsersController:

    public function edit($id)
    {
        $user = User::find($id);
        if (is_null($user))
        {
            return Redirect::route('users.index');
        }
        return View::make('users.edit', compact('user'));
    }

So when the edit request is fired, it will hit the edit method described in the preceding code snippet. We would need to find whether the user exists in the database. So we use our user model to query the ID using the following line of code:

$user = User::find($id);

Eloquent object’s find method will query the database just like a normal SQL.

Select * from users where id = $id

Then we will check whether the object we received is empty or not. If it is empty, we would just redirect the user to our list user’s interface. If it is not empty, we would direct the user to the user’s edit view with our Eloquent object as a compact array.

So let’s create our edit user view at app/resouces/users/edit.blade.php, as follows:

@extends('users.scaffold')

@section('main')

<h1>Edit User</h1>
{{ Form::model($user, array('method' => 'PATCH', 'route' => array('users.update', $user->id))) }}
    <ul>
        <li>
            {{ Form::label('username', 'Username:') }}
            {{ Form::text('username') }}
        </li>
        <li>
            {{ Form::label('password', 'Password:') }}
            {{ Form::text('password') }}
        </li>
        <li>
            {{ Form::label('email', 'Email:') }}
            {{ Form::text('email') }}
        </li>
        <li>
            {{ Form::label('phone', 'Phone:') }}
            {{ Form::text('phone') }}
        </li>
        <li>
            {{ Form::label('name', 'Name:') }}
            {{ Form::text('name') }}
        </li>
        <li>
            {{ Form::submit('Update', array('class' => 'btn btn-info')) }}
            {{ link_to_route('users.show', 'Cancel', $user->id, array('class' => 'btn')) }}
        </li>
    </ul>
{{ Form::close() }}

@if ($errors->any())
    <ul>
        {{ implode('', $errors->all('<li class="error">:message</li>')) }}
    </ul>
@endif

@stop

Here we are extending our users’ layout as always and defining the main section. Now in the main section, we are using the Form helper to generate a proper REST request for our controller.

{{ Form::model($user, array('method' => 'PATCH', 'route' => array('users.update', $user->id))) }}

Now, you may have not dealt with the method PATCH as we only know of two protocols, GET and POST, as most browsers generally support only these two methods. The REST method for editing is PATCH, and what Laravel does is that it creates a hidden token so it knows which method to call. So the preceding code generates the following code:

<form method="POST" action="http://ch3.sr/users/1" accept-charset="UTF-8">
<input name="_method" type="hidden" value="PATCH">

It actually fires a POST method for browsers that are not capable for handling the PATCH method. Now, when a user submits this form, it will send a request to the update method of UsersController via the resourceful Controller we set in routes.php.

Here is the update method of UsersController:

public function update($id)
    {
        $input = Input::all();
        $validation = Validator::make($input, User::$rules);
        if ($validation->passes())
        {
            $user = User::find($id);
            $user->update($input);
            return Redirect::route('users.show', $id);
        }
return Redirect::route('users.edit', $id)
            ->withInput()
            ->withErrors($validation)
            ->with('message', 'There were validation errors.');
    }

Here Laravel will pass the ID of the user we are editing in the update method. We can use this ID to find the user via our user model’s Eloquent object’s find method. Then we will update the Eloquent object with an input array just like we did in the insert operation.

Deleting user information

To delete a user we can use the destroy method. If you go to our user lists view, you can find the following delete link’s generation code:

{{ Form::open(array('method' => 'DELETE', 'route' => array('users.destroy', $user->id))) }}
{{ Form::submit('Delete', array('class' => 'btn btn-danger')) }}
{{ Form::close() }}

The preceding code is handled by Laravel similar to the way in which it handles the PATCH method. Laravel will generate a post request with the hidden method token set as PATCH, which it can recognize when it hits the Laravel request object.

At UsersController this request will hit the destroy() method as follows:

    public function destroy($id)
    {
        User::find($id)->delete();
        return Redirect::route('users.index');
    }

Laravel will directly send id to the destroy method, so all we have to do is use our user model and delete the record with its delete method. If you noticed Eloquent allows us to chain methods. Isn’t it sweet? So there would be no queries but just one line to delete a user.

That’s one of the reasons to use Eloquent objects in your projects. It allows you to quickly interact with the database and you can use objects to match your business logic.

Adding pagination to our list users

One of the painful tasks most developers face often is that of pagination. With Laravel it’s no more the case, as Laravel provides a simple approach to set pagination to your pages.

Let’s try to implement pagination to our list user’s method. To set pagination we can use the paginate method with Laravel’s Eloquent object. Here is how we can do that:

public function index()
{
  $users = User::paginate(5);
  return View::make('users.index', compact('users'));
}

The preceding code is the index method of the UsersController class, which we were using previously for getting all the users with User::all(). We just used the paginate method to find five records from the database. Now in our list users view, we can use the following code to display pagination links:

{{ echo $users->links(); }}
Here the links() method will generate pagination links for you. And best part, Laravel will manage the code for pagination. So all you have to do is use paginate method with your eloquent object and links method to display generated links.

 

Wrapping up

So we have set up our simple CRUD application and now we know how easy it is with Laravel to set up CRUD operations. We have seen Eloquent Laravel’s database ORM that makes working with a database simple and easy. We have learned how to list users, create new users, edit users, delete users, and how to add pagination to our application.

The End. https://www.dunebook.com/

Create a CRUD Application with Laravel 5.2 (Part-5)

Creating new users

Now as we have listed our users, let’s write the code for creating new users. To create a new user, we will need to create the Controller method and bind the view for displaying the new user form. We would need to create the Controller method for saving the user too. Now as we have bound the resourceful Controller, we don’t need to create separate routes for each of our request. Laravel will handle that part if we use REST methods.

So first let’s edit the controller at /app/http/controllers/UsersController.php to add a method for displaying the view:

    public function create()
    {
        return View::make('users.create');
    }

This will call a view at /app/resources/users/create.blade.php. So let’s define our create.blade.php view as follows:

@extends('layouts.users')

@section('main')

<h1>Create User</h1>

{{ Form::open(array('route' => 'users.store')) }}
    <ul>

        <li>
            {{ Form::label('name', 'Name:') }}
            {{ Form::text('name') }}
        </li>

        <li>
            {{ Form::label('username', 'Username:') }}
            {{ Form::text('username') }}
        </li>

        <li>
            {{ Form::label('password', 'Password:') }}
            {{ Form::password('password') }}
        </li>

        <li>
            {{ Form::label('password', 'Confirm Password:') }}
            {{ Form::password('password_confirmation') }}
        </li>        

        <li>
            {{ Form::label('email', 'Email:') }}
            {{ Form::text('email') }}
        </li>

        <li>
            {{ Form::label('phone', 'Phone:') }}
            {{ Form::text('phone') }}
        </li>


        <li>
            {{ Form::submit('Submit', array('class' => 'btn')) }}
        </li>
    </ul>
{{ Form::close() }}

@if ($errors->any())
    <ul>
        {{ implode('', $errors->all('<li class="error">:message</li>')) }}
    </ul>
@endif

@stop

Let’s try to understand our preceding view. Here we are extending the users layout we created in our List Users section. Now in the main section, we are using Laravel’s Form helper to generate our form. This helper generates HTML code via its methods such as label, text, and submit.

Refer to the following code:

{{ Form::open(array('route' => 'users.store')) }}

The preceding code will generate the following HTML code:

<form method="POST" action="http://localhost/users" accept-charset="UTF-8">

As you can see it’s really convenient for us to not worry about linking things correctly. Now let’s create our store method to store our form data into our users table:

public function store()
    {
        $input = Input::all();
        $validation = Validator::make($input, User::$rules);

        if ($validation->passes())
        {
            User::create($input);

            return Redirect::route('users.index');
        }

        return Redirect::route('users.create')
            ->withInput()
            ->withErrors($validation)
            ->with('message', 'There were validation errors.');
    }

Here we are first validating all the input that came from the user. The Input::all () function fetches all the $_GET and $_POST variables and puts it into a single array. The reason why we are creating the single input array is so we can check that array against validation rules’ array. Laravel provides a very simple Validation class that can be used to check validations. We could use it to check whether validations provided in the rules array are followed by the input array by using the following line of code:

$validation = Validator::make ($input, User::$rules);

Rules can be defined in an array with validation attributes separated by the column “|”. Here we are using User::$rules where User is our Model and it will have following code:

class User extends Eloquent {

  protected $guarded = array('id');
  protected $fillable = array('name', 'email');

  public static $rules = array(
    'name' => 'required|min:5',
    'email' => 'required|email'
  );
}

As you can observe we have defined two rules mainly for name and e-mail input fields. If you are wondering about $guarded and $fillable variables, these variables are used to prevent mass assignment. When you pass an array into your Model’s create and update methods, Laravel tries to match the right columns and sets values in the database. Now for instance, if a malicious user sends a hidden input named id and changes his ID via the update method of your form, it could be a huge security hole; to prevent this, we should define the $guarded and $fillable arrays. The $guarded array will guard the columns defined in the guarded array, that is, it will prevent anyone from changing values in that column. The $fillable array will only allow elements defined in $fillable to be updated.

Now we can use the $validation instance we created to check for validations.

$result = $validation->passes();
echo $result; // True or false

If you see our code now, we are checking for validation via the passes() method in our Store() method of UserController. Now if validation gets passed, we can use our user Model to store data into our database. All you need to do is call the Create method of the Model class with the $input array. So refer to the following code:

User::create($input);

The preceding code will store our $input array into the database; yes, it’s equivalent to your SQL query.

Insert into user(name,password,email,city) values (x,x,..,x);

Here we have to fill either the $fillable or $guarded array in the model, otherwise, Laravel will throw a mass assignment exception. Laravel’s Eloquent object automatically matches our input array with the database and creates a query based on our input array. Don’t you think this is a simple way to store input into the database? If user data is inserted, we are using Laravel’s redirect method to redirect it to our list of users’ pages. If validation fails, we are sending all of the input with errors from the validation object into our create users form.

Source: https://www.dunebook.com

 

Create a CRUD Application with Laravel 5.2 (Part-4)

Now let’s look at the View part. Before that, we need to know about Blade. Blade is a templating engine provided by Laravel. Blade has a very simple syntax, and you can determine most of the Blade expressions within your view files as they begin with @. To print anything with Blade, you can use the {{ $var }} syntax. Its PHP-equivalent syntax would be:

<?php echo $var; ?>

Now back to our view; first of all, we need to create a view file at /resources/views/users/index.blade.php, as our statement would return the view file from users.index. We are passing a compact users array to this view. So here is our index.blade.php file:

@section('main')

<h1>All Users</h1>

<p>{{ link_to_route('users.create', 'Add new user') }}</p>

@if ($users->count())
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>Username</th>
        <th>Password</th>
        <th>Email</th>
        <th>Phone</th>
        <th>Name</th>
            </tr>
        </thead>

        <tbody>
            @foreach ($users as $user)
                <tr>
                    <td>{{ $user->username }}</td>
          <td>{{ $user->password }}</td>
          <td>{{ $user->email }}</td>
          <td>{{ $user->phone }}</td>
          <td>{{ $user->name }}</td>
                    <td>{{ link_to_route('users.edit', 'Edit', array($user->id), array('class' => 'btn btn-info')) }}</td>
                    <td>
          {{ Form::open(array('method' 
=> 'DELETE', 'route' => array('users.destroy', $user->id))) }}                       
                            {{ Form::submit('Delete', array('class' => 'btn btn-danger')) }}
                        {{ Form::close() }}
                    </td>
                </tr>
            @endforeach
              
        </tbody>
      
    </table>
@else
    There are no users
@endif

@stop

Let’s see the code line by line. In the first line we are extending the user layouts via the Blade template syntax @extends. What actually happens here is that Laravel will load the layout file at /app/views/layouts/user.blade.php first.

Here is our user.blade.php file’s code:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
        <style>
            table form { margin-bottom: 0; }
            form ul { margin-left: 0; list-style: none; }
            .error { color: red; font-style: italic; }
            body { padding-top: 20px; }
        </style>
    </head>

    <body>

        <div class="container">
            @if (Session::has('message'))
                <div class="flash alert">
                    <p>{{ Session::get('message') }}</p>
                </div>
            @endif

            @yield('main')
        </div>

    </body>

</html>

Now in this file we are loading the Twitter bootstrap framework for styling our page, and via yield('main') we can load the main section from the view that is loaded. So here when we load http://localhost/laravel/public/users, Laravel will first load the users.blade.php layout view and then the main section will be loaded from index.blade.php.

Now when we get back to our index.blade.php, we have the main section defined as @section('main'), which will be used by Laravel to load it into our layout file. This section will be merged into the layout file where we have put the @yield ('main') section.

We are using Laravel’s link_to_route method to link to our route, that is, /users/create. This helper will generate an HTML link with the correct URL. In the next step, we are looping through all the user records and displaying it simply in a tabular format. Now if you have followed everything, you will be greeted by the following screen:

Crud-User

Create a CRUD Application with Laravel 5.2 (Part-3)

As you can see, resource Controller really makes your work easy. You don’t have to create lots of routes. Also Laravel ‘s artisan-command-line generator can generate resourceful Controllers, so you will write very less boilerplate code. And you can also use the following command to view the list of all the routes in your project from the root of your project, launching command line:

$ php artisan routes

Now let’s get back to our basic task, that is, reading users. Well now we know that we have UserController.php at /app/controller with the index method, which will be executed when somebody launches http://localhost/laravel/public/users. So let’s edit the Controller file to fetch data from the database.

Well as you might remember, we will need a Model to do that. But how do we define one and what’s the use of Models? You might be wondering, can’t we just run the queries? Well Laravel does support queries through the DB class, but Laravel also has Eloquent that gives us our table as a database object, and what’s great about object is that we can play around with its methods. So let’s create a Model.

If you check your path /app/User.php, you will already have a user Model defined. It’s there because Laravel provides us with some basic user authentication. Generally you can create your Model using the following code:

class User extends Eloquent {}

Now in your controller you can fetch the user object using the following code:

$users = User::all();
$users->toarray();

Yeah! It’s that simple. No database connection! No queries! Isn’t it magic? It’s the simplicity of Eloquent objects that many people like in Laravel.

But you have the following questions, right?

  • How does Model know which table to fetch?
  • How does Controller know what is a user?
  • How does the fetching of user records work? We don’t have all the methods in the User class, so how did it work?

Well models in Laravel use a lowercase, plural name of the class as the table name unless another name is explicitly specified. So in our case, User was converted to a lowercase user and used as a table to bind with the User class.

Models are automatically loaded by Laravel, so you don’t have to include the reference of the Model file. Each Model inherits an Eloquent instance that resolves methods defined in the model.php file at vendor/Laravel/framework/src/Illumininate/Database/Eloquent/ like all, insert, update, delete and our user class inherit those methods and as a result of this, we can fetch records via User::all().

So now let’s try to fetch users from our database via the Eloquent object. I am updating the index method in our app/controllers/UsersController.php as it’s the method responsible as per the REST convention we are using via resource Controller.

public function index()
  {

        $users = User::all();

return View::make(‘users.index’, compact(‘users’));
}

 

Create a CRUD Application with Laravel 5.2 (Part-2)

Listing the users – read users from database

Let’s read users from the database. We would need to follow the steps described to read users from database:

  • A route that will lead to our page
  • A controller that will handle our method
  • The Eloquent Model that will connect to the database
  • A view that will display our records in the template

So let’s create our route at /app/http/routes.php. Add the following line to the routes.php file:

Route::resource('users', 'UserController');

If you have noticed previously, we had Route::get for displaying our page Controller. But now we are using resource. So what’s the difference?

In general we face two types of requests during web projects: GET and POST. We generally use these HTTP request types to manipulate our pages, that is, you will check whether the page has any POST variables set; if not, you will display the user form to enter data. As a user submits the form, it will send a POST request as we generally define the <form method="post"> tag in our pages. Now based on page’s request type, we set the code to perform actions such as inserting user data into our database or filtering records.

What Laravel provides us is that we can simply tap into either a GET or POST request via routes and send it to the appropriate method. Here is an example for that:

Route::get('/register', 'UserController@showUserRegistration');
Route::post('/register', 'UserController@saveUser');

See the difference here is we are registering the same URL, /register, but we are defining its GET method so Laravel can call UserController class’ showUserRegistration method. If it’s the POST method, Laravel should call the saveUser method of the UserController class.

You might be wondering what’s the benefit of it? Well six months later if you want to know how something’s happening in your app, you can just check out the routes.php file and guess which Controller and which method of Controller handles the part you are interested in, developing it further or solving some bug. Even some other developer who is not used to your project will be able to understand how things work and can easily help move your project. This is because he would be able to somewhat understand the structure of your application by checking routes.php.

Now imagine the routes you will need for editing, deleting, or displaying a user. Resource Controller will save you from this trouble. A single line of route will map multiple restful actions with our resource Controller. It will automatically map the following actions with HTTP verbs:

HTTP VERB ACTION
GET READ
POST CREATE
PUT UPDATE
DELETE DELETE

On top of that you can actually generate your Controller via a simple command-line artisan using the following command:

$ php artisan make:controller usercontroller

This will generate UsersController.php with all the RESTful empty methods, so you will have an empty structure to play with. Here is what we will have after the preceding command:

class UserController extends BaseController {

  /**
   * Display a listing of the resource.
   *
   * @return Response
   */
  public function index()
  {
    //
  }

  /**
   * Show the form for creating a new resource.
   *
   * @return Response
   */
  public function create()
  {
    //
  }

  /**
   * Store a newly created resource in storage.
   *
   * @return Response
   */
  public function store()
  {
    //
  }

  /**
   * Display the specified resource.
   *
   * @param  int  $id
   * @return Response
   */
  public function show($id)
  {
    //
  }

  /**
   * Show the form for editing the specified resource.
   *
   * @param  int  $id
   * @return Response
   */
  public function edit($id)
  {
    //
  }

  /**
   * Update the specified resource in storage.
   *
   * @param  int  $id
   * @return Response
   */
  public function update($id)
  {
    //
  }

  /**
   * Remove the specified resource from storage.
   *
   * @param  int  $id
   * @return Response
   */
  public function destroy($id)
  {
    //
  }
  
}

Now let’s try to understand what our single line route declaration created relationship with our generated Controller.
HTTP VERB Path Controller Action/method
GET /Users Index
GET /Users/create Create
POST /Users Store
GET /Users/{id} Show (individual record)
GET /Users/{id}/edit Edit
PUT /Users/{id} Update
DELETE /Users/{id} Destroy

Source: https://www.dunebook.com