## Installation:
	$ composer install
	$ cp .env.example .env
	$ php artisan key:generate
	# make your DB, and set the configuration in the env file
	$ php artisan migrate 
	$ php artisan db:seed 

## The most important things are:
 - Clean code.
 - TDD Process [Read This](https://www.5balloons.info/laravel-tdd-beginner-crud-example/)
 - write comments for each method demonestrates the action of the method the params it recieves and the type of the return value.
 - Test classes for each single operation
 - Clean code.
 - Clean readable code.
 - Joins, fields Type, consider add index to fields which will be in where condition or order by.
 -  Use sub-queries wisely 
 - Variable names: CamelCase "$userInfo".
 - Method names: CamelCase "createUser".
 - Class Names: Upper camel case "PagesDescription"
 - Constants:  Upper case "PUBLIC_FOLDER_PATH"
 - Don't use '_' anywhere except DB table and fields name, constants, and enum values (which are constants).
 - Do not user Uppercase in SQL, as mentioned above use underscore to seperate words


> Take a look at module Categories
In Test folder, database folder, App\Requests, models, controllers, and view 

##  Notes:

1- use resource controller for each of our components

	$ php artisan make:model Photo -a

	# Set the configratio of your file, add coments demonstarte the use of the field and the use of the table
	# $table->engine = 'InnoDB'; in tables with transactions and relations

	$ php artisan migrate --path database\migrations\2020_03_26_123015_create_photos_table.php

	# move controller to Admin folder 
	# Do not forget to change the namespace of the controller
	$ move app\http\Controllers\PhotoController.php app\http\controllers\admin\
	# Add this line after namespace line
	use App\Http\Controllers\Controller;
	
	# for establishing the Unit Test class of Photos module
	$ php artisan make:test PhotosTest

	# The route in admin group is 
	# Route::resource('photos', 'PhotoController');

	# @method('PUT') in form if this is update form
	
	# Delete any row via ajax request and set method type in the ajax request to `delete`

	# Route in the frontend is module/{id}/{slug?}

2- Each module has 2 tables:
	- Basic info Table like the id, image,published_date, visitors_num, ...ect `pages`
	- Description table, which contains module_id like article_id, language_id: joined with language table, title, description, slug, keywords, meta_description. `EX: pages_description`

	- so consider joining in migeration files, and models

3- Rules of validation done via form request classes to make controller classes clean 
	`$ php artisan make:request PhotoRequest`
	# Please remeber to set the return of method `authorize` in the generated Request class to true
	# Take a look at `LanguageController` And `LanguageRequest`


4- redirect by
	` return redirect('form')->withInput(); `
	and in View
	` <input name="title" class="form-control" value="{{ old('title', 'DBValue') }}" /> `


5- use csrf tokens in forms and ajax requests

6- soft delete & make archive in every page with delete

7- there is `file-manager` to upload and set images in editors and images fields 
`see language.blade.php`

7- in any opertion contains more than one query , use transaction


8- use cursor in retrivig data
```php
foreach (DBRespose->cursor() as $row) {
	//
}
```

9- Pagination

10- Resize Images Helper

```php
/** At the top of the controller */
use App\Helpers\ImageHelper;

/** In the Controller */
$thumbImageURL = ImageHelper::resize($originalImageInPublicDir, 200, 100);

/** Note that the thumbnails uploaded to `uploads/images/thumbnails` */

```

11- Upload Images Helper

``` # You will not need it in dashboard as there is a filemanager ```

```php
/** At the top of the controller */
use App\Helpers\ImageHelper;


/** In the form request class */

public function rules()
{
	return [
		......
		'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
	];
}

/** In the Controller */
$uploadedFile = ImageHelper::upload($request->file('image'));

/** Note that the original images uploaded to `uploads/images` and thumbnails uploaded to `uploads/images/thumbnails` */

```

## Test Report
[TDD demo](https://www.5balloons.info/laravel-tdd-beginner-crud-example/)
Use Transaction in every test class, to roll back any new inserted data

```php
use Illuminate\Foundation\Testing\DatabaseTransactions;

class PhotosTest extends TestCase
{
    use DatabaseTransactions;
```

``` $ php artisan test --env=testing  --testdox-html report.html ```

## API
	
	$ php artisan make:controller API/LanguageController --api
	# In the api.php route file
	# Route::apiResource('/languages', 'API\LanguageController');

	# To handel what will be returned in any API request
	$ php artisan make:resource Language

- Do not forget to override the Request `failedValidation` method in Request class, which in our case is `Requests\LanguageRequest`

```php

/** At the top of the class */

use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;

/** In the class */

/**
	* Handle a failed validation attempt.
	* 
	* Override the parent method action if the request is for AJAX 
	* 
	* @param  \Illuminate\Contracts\Validation\Validator  $validator
	* @return void
	*
	* @throws \Illuminate\Validation\ValidationException
	*/
protected function failedValidation(Validator $validator)
{
	if(\Request::wantsJson()){
		$errors = (new ValidationException($validator))->errors();
		throw new HttpResponseException(response()->json(['errors' => $errors], 400));
	} else {
		parent::failedValidation($validator);
	}
}
```

## Last thing
- Deelete test routes and its controllers
- Cache route after publish
``` $ php artisan route:cache ```
