8000 GitHub - dyanagi/Laravel: Laravel
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jul 12, 2019. It is now read-only.

dyanagi/Laravel

Repository files navigation

Laravel

A Laravel practise project. This project uses:

  • PHP 7
  • Laravel 5.6
  • XAMPP
  • Bootstrap 4.x

Random Notes

Useful Commands

  • Clear the cash of views: php artisan view:clear
  • Create a controller class: php artisan make:controller PostController
  • Create a model class: php artisan make:model Flight

Learning Resources

Laravel IDE Helper

https://github.com/barryvdh/laravel-ide-helper

Request and Response

Dependency Injection (a good practise in general)

$request->input('mail')

Facades

Request::input("mail')

RSRF Protection

<input type="hidden" name="_token" value="{{ csrf_token() }}">

Shorter syntax

{{ csrf_field() }}

Validations

Validation in Router

// routes/web.php

$validation = $validator->make($request->all(), [
    'title' => 'required|min:5',
    'content' => 'required|min:10'
]);
if ($validation->fails()) {
    return redirect()->back()->withErrors($validation);
}

Validation in Controller

// PostController.php

$this->validate($request, [
    'title' => 'required|min:5',
    'content' => 'required|min:10'
]);

// automatically pass the error and redirect if there is an error

Routes

With no controller

Route::get('/', function () {
    return view('blog.index');
})->name('blog.index');

With a controller

Route::get('/', 'PostController@getIndex')->name('blog.index');

Structured route syntax

Route::get('/', [
    'uses' => 'PostController@getIndex',
    'as => 'blog.index'
]);

Saving one-time data (Flashed Session Data) in route

https://laravel.com/docs/5.6/redirects#redirecting-with-flashed-session-data

return redirect()->route('admin.index')->with('info', 'Post edited, new Title: ' . $request->input('title'));

Blade Template

https://laravel.com/docs/5.6/blade

Using a master layout

File: layouts/admin.blade.php

<div class="container">
    @yield('content')
</div>
File: admin/index.blade.php

@extends('layouts.admin')

@section('content')
    something goes here
@endsection

if

@if(Session::has('info'))
    something goes here
@else
    something goes here
@endif

foreach

@foreach($posts as $post)
    ...
    <a href="{{ route('admin.edit', ['id' => array_search($post, $posts)]) }}">Edit</a>
    ...
@endforeach

for

@for($i = 0; $i < 5; $i++)
    <p>{{ $i + 1 }}.Iteration</p>
@endfor

Display data

<p>{{ "Hello" }}</p>
<p>{{ $name }}</p>
<p>{{ 2 == 2 ? "Equal" : "Does not equal" }}</p>
<p>{{ 2 == 3 ? "Equal" : "Does not equal" }}</p>

XSS Protected

{{ "<script>alert('Hello');</script>" }}

Raw data - Not protected

{!! "<script>alert('Hello');</script>" !!}}

About

Laravel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0