31
Laravel The Right Way

Laravel the right way

Embed Size (px)

Citation preview

Page 1: Laravel   the right way

LaravelThe RightWay

Page 2: Laravel   the right way

marabesi

@MatheusMarabesi

Page 3: Laravel   the right way
Page 4: Laravel   the right way

DISCLAIMER

Page 5: Laravel   the right way

MODELS

Page 6: Laravel   the right way

WRONG

Page 7: Laravel   the right way

MUCH BETTER

Page 8: Laravel   the right way

CONTROLLERS

Page 9: Laravel   the right way

WRONG

Page 10: Laravel   the right way
Page 11: Laravel   the right way

1

Page 12: Laravel   the right way

1

2

Page 13: Laravel   the right way

1 BETTER

2

3

Page 14: Laravel   the right way
Page 15: Laravel   the right way

pingpong-labs/modules

Page 16: Laravel   the right way

modules/ ├── Blog/ ├── Assets/ ├── Config/ ├── Console/ ├── Database/ ├── Migrations/ ├── Seeders/ ├── Entities/ ├── Http/ ├── Controllers/ ├── Middleware/ ├── Requests/ ├── routes.php ├── Providers/

Page 17: Laravel   the right way

D.I

Page 18: Laravel   the right way

public function newDeal(Request $request) { $data = $request->all(); // some stuff $page = "new_deal/new_deal_" . $data['page'];

return view($page, [ 'active_step' => $data['page'], 'template_step' => 'app_deal_steps', 'origin' => 'new_deal', 'title' => 'New Deal', 'customers' => new App\Deals(), ]);}

Page 19: Laravel   the right way

public function newDeal(Request $request, App\Deals $deal) { $data = $request->all();

// some stuff

$page = "new_deal/new_deal_" . $data['page'];

return view($page, [ 'active_step' => $data['page'], 'template_step' => 'app_deal_steps', 'origin' => 'new_deal', 'title' => 'New Deal', 'customers' => $deal, ]);}

Page 20: Laravel   the right way

public function store(Request $request){ $result['message'] = 'Success'; try { $data = $request->all();

$userId = Auth::user()->id;

$company = \App::make(Company::class) ->where('created_by', $userId) ->first();

$company->save($data); } catch (\Exception $error) { $result['message'] = $error->getMessage(); }

return response()->json($result);}

Page 21: Laravel   the right way

TESTING

Page 22: Laravel   the right way

PHPUnit_Framework_TestCase

Page 23: Laravel   the right way

PHPUnit_Framework_TestCase

TestCase

Page 24: Laravel   the right way

PHPUnit_Framework_TestCase

TestCase

Page 25: Laravel   the right way

Class \TestCase

Page 26: Laravel   the right way

padraic/mockery

Page 27: Laravel   the right way

public function update(Request $request){ // do something

return Auth::user()->id;}

Page 28: Laravel   the right way
Page 29: Laravel   the right way

WHAT CAN I DO ?

Page 30: Laravel   the right way
Page 31: Laravel   the right way

+