Skip to content

Instantly share code, notes, and snippets.

View moradi-morteza's full-sized avatar
💭
I may be slow to respond.

Developer moradi-morteza

💭
I may be slow to respond.
  • Tehran,Qom
View GitHub Profile
@moradi-morteza
moradi-morteza / validation.php
Last active December 30, 2019 13:46
[validation] #LaravelT
//VALIDATION
// 1-post data to controller method
// inside controller :
public function store(Request $request){
// $validator = $request->validate([
// 'name' => 'required',
// 'age' => 'required',
@moradi-morteza
moradi-morteza / middelware.php
Last active December 22, 2019 17:56
[middelware] #LaravelT
//php artisan down - CheckForMaintenanceMode Middleware in Kernel.php is an example of middleware
// middle ware should be define in Kernel.php
// it can be effect in whole website or just certain route
// you can run middle ware in constructor method of controller
// in counstrucor method you can use (only) and (except) method to say meddle ware affect in what method
// 2 type of middleware exist 1:befor 2:after
@moradi-morteza
moradi-morteza / routing.php
Last active December 22, 2019 17:57
[routing] #LaravelT
php artisan route:list // show all list of routes
//orginal ---------------------------------------
Route::get('/','HomeController@index');
//without method name ----------------------------
// if you not mention name of method so you should use __invoke():
Route::get('/{name}','HomeController');
@moradi-morteza
moradi-morteza / request.php
Last active January 8, 2020 05:28
[request] #LaravelT
//Request $request
You may also retrieve all of the input data as an array using the all method:
//$request->all() : return its data for post method in array type
//$request->all() : return its data for get method in query string like : http://127.0.0.1:8000/admin/products?name=ali in array
@moradi-morteza
moradi-morteza / response.php
Last active December 22, 2019 17:54
[response] #LaravelT
// response should be an object(should be have toString method) or string or array , it can not be a boolean
// if you return an array laravel by default convert it to json
retrun ["name"=>"ali","age"=>25];
// laravel prefer response
return response('hello',201,[
'SAMPLE_HEADER'=>'VALUE'
]);
return response('hello',201)->header('second_header','salam');
@moradi-morteza
moradi-morteza / session.php
Last active December 22, 2019 17:54
[session] #LaravelT
// set session----------------------
session()->put('name','morteza');// or
session(['name'=>'hamid','age'=>23]);
// to get session
echo session()->get('name'); //or
echo session('name','default');
// check session---------------------
session('name',null);
@moradi-morteza
moradi-morteza / database.php
Last active December 22, 2019 17:54
[database] #LaravelT
// if you want to connect in certain database use
DB::connection('name_of_connection_in_database.config');
DB::connection('mysql')->getPdo(); // return an object pdo
// if you not mention name of connection it by default use env connection name like
DB::table('posts'); // in env its set by default mysql (mysqli in this file its just a name 'drive' is importent
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
@moradi-morteza
moradi-morteza / model.php
Last active December 22, 2019 17:54
[model] #LaravelT
$post = new Post();
$post->title = "hello";
$post->des = "des"
$post->save();
// if send extra data that is not in table it give you error
//---------------------------
@moradi-morteza
moradi-morteza / seed.php
Last active November 6, 2020 08:23
[seed] #LaravelT
// without Factory----------------
// 1- command create
php artisan make:seed UserTableSeeder
//2- classes
class DatabaseSeeder extends Seeder{
public funtion run(){
Schema::disableForeignKeyConstraints();
$this->call(UserTableSeeder::class);
@moradi-morteza
moradi-morteza / blade.php
Last active December 22, 2019 17:52
[blade] #LaravelT
// in file template user
<html>
<body>
@yield('header')
@yield('content')
@yield('footer')
</body>
</html>
// then in your second file view-one.blade.php
@extends('template')