This is a community collaborative translation of the article, has been translated, more information please click
Introduction to collaborative translation 。


When you take on a new project, you can feel out of your depth, especially if you’re not familiar with programming. So where do we start? What parts of the project code do we need to focus on? Let’s look at a few common parts of the Laravel project.

Project documentation

readme

1
retranslation

Summer

If you’re not lucky (and most of the time you are), the project you’re working on doesn’t have any documentation. The lack of documentation is not entirely a bad thing, because in this case, you have the opportunity to personally document your team. You and your colleagues, as well as the new developers you bring in, will be grateful to you in the future.

“Why is that?”
“How to Proceed”

0
retranslation

Summer

composer.json

Composer
composer.json
composer.json
composer.lock
here
composer.json
require

{" require ": {" PHP" : "> = 7.1.3", "fideloper/proxy" : "4.0", "laravel/framework" : "5.6. *", "laravel/tinker" : "1.0"}}Copy the code

In this example, we have a project based on Laravel 5.6. It relies on two other packages, as well as at least version 7.1.3 of PHP. You will most likely see more dependency packages in your project, and version numbers may change.


0
retranslation

Summer
https://laravel-china.org/docs/laravel/{VERSION}
https://laravel.com/api/{VERSION}
Laravel-china.org/docs/larave…
laravel.com/api/5.6
docs
api

After you have reviewed the Laravel document, you can move on to other dependent documents. You can go to Packagist (this is used by the Composer expansion pack warehouse) for more information on the dependence, the corresponding extension address to https://packagist.org/packages/ {VENDOR} / {PACKAGE}, Such as packagist.org/packages/fi… .

On the home page of each Packagist project, there is an introduction to the extension pack, the version number, the repository address (such as GitHub), the complete readme file, and other useful information. The information from the project home page is enough to give you an idea of what the extension package is and what part of your project it will perform. In this way, continue to learn about the other dependencies listed in the composer. Json file for your project application.


0
retranslation

Summer

routing

closure

You can find the routing configuration file in the following location of the project:

  • Laravel 5.3 +routes/*.php
  • Laravel 5.0 to 5.2app/Http/routes.php
  • Laravel 4.2 app/routes.php


0
retranslation

Summer

Routing “trap”

Sometimes, locating a route based on a specific URL takes a little ingenuity.

/users/123/profile
users/{id}/profile
Routing group

Route::prefix('users')->group(function () {
    Route::get('{id}/profile', 'UsersController@profile');
});
Copy the code

users
{id}/profile

Another pit is Route:: Resource() (and Route::apiResource() in newer versions).


0
retranslation

Summer
Route::resource()
Route::resource('dogs', 'DogController');

Route::group(['prefix' => 'dogs'], function () {
    Route::get('/', 'DogsController@index')->name('dogs.index');
    Route::get('create', 'DogsController@create')->name('dogs.create');
    Route::post('/', 'DogsController@store')->name('dogs.store');
    Route::get('{id}', 'DogsController@show')->name('dogs.show');
    Route::get('{id}/edit', 'DogsController@edit')->name('dogs.edit');
    Route::put('{id}', 'DogsController@update')->name('dogs.update');
    Route::delete('{id}', 'DogsController@destroy')->name('dogs.destroy');
});
Copy the code

dogs/{id}/edit
Route::resource()

0
retranslation

Summer
Route::resource()
The document
route:list

php artisan route:list
Copy the code

The route:list command provides complete details of each route, including HTTP request style, specific URI, route name, action information (that is, controllers and methods), and middleware information configured for each route.


0
retranslation

Summer

Service provider

The official documentation

The service provider is the boot center for all Laravel applications. Your application and all of Laravel’s core services are bootstrapped through the service provider.

By bootstrapping, we mean registration, such as registration of service container bindings, event listeners, middleware, and even routes. The service provider is central to configuring your application.

app/providers

In older versions of Laravel, such as 4.2, you would find similar functionality in the global.php file, since service providers were usually only used in packages at that time.


0
retranslation

Summer

test

The code base includes test suites that show you how the application works and how it responds next. It can provide valuable clues to the boundary handling of applications. Of course, just like the code base documentation, the test files that accompany your application may not exist, be few, or even obsolete.

Just like writing project documentation, writing application matching tests can help you learn more about your project and improve the quality of your code. You might stumble upon and fix bugs, remove useless code, or add test coverage to important classes in your project.


0
retranslation

Summer

tool

Laravel Debugbar

The end of the

Twitter

0
retranslation

Summer

All translations in this article are for study and communication purposes only. Please note the translator, source, and link to this article


Our translation work is in accordance with
CCIf our work has violated your rights and interests, please contact us immediately.