Last active
December 14, 2021 06:45
-
-
Save GabrieliRoldao/06fa0be176b0e9913970085864fdeafa to your computer and use it in GitHub Desktop.
Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('layouts.admin-master') | |
@section('styles') | |
<link rel="stylesheet" href="{{ URL::asset('src/css/form.css') }}" type="text/css" /> | |
@endsection | |
@section('content') | |
<div class="container"> | |
@include('includes.info-box') | |
<form action="{{route('admin.blog.post.create')}}" method="post"> | |
<div class="input-group"> | |
<label for="title">Titulo</label> | |
<input type="text" name="title" id="title" {{$errors->has('title') ? 'class=has-error' : ''}} | |
value = "{{Request::old('title')}}"/> | |
</div> | |
<div class="input-group"> | |
<label for="author">Autor</label> | |
<input type="text" name="author" id="author" {{$errors->has('author') ? 'class=has-error' : ''}} | |
value ="{{Request::old('author')}}"/> | |
</div> | |
<div class="input-group"> | |
<label for="category_select">Categorias</label> | |
<select name="category_select" id="category_select"> | |
<option value="Categoria teste ID">Categoria teste</option> | |
</select> | |
<button type="button" class="btn">Adicionar categoria</button> | |
<div class="added-categories"> | |
<ul></ul> | |
</div> | |
<input type="hidden" name="categorias" id="categories" /> | |
</div> | |
<div class="input-group"> | |
<label for="body">Post</label> | |
<textarea name="body" id="body" rows="12" {{$errors->has('body') ? 'class=has-error' : ''}} {{Request::old('body')}}></textarea> | |
</div> | |
<button type="submit" class="btn">Criar post</button> | |
<input type="hidden" name="_token" value="{{Session::token()}}"/> | |
</form> | |
</div> | |
@endsection | |
@section('scripts') | |
<script type="text/javascript" src="{{URL::asset('src/js/posts.js')}}"/> | |
@endsection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@section('styles') | |
<link rel="stylesheet" href="{{ URL::asset('src/css/common.css') }}"/> | |
@append | |
@if(Session::has('fail')) | |
<section class="info-box fail"> | |
{{ Session::get('fail') }} | |
</section> | |
@endif | |
@if(Session::has('success')) | |
<section class="info-box success"> | |
{{ Session::get('success') }} | |
</section> | |
@endif | |
@if(count($errors)>0) | |
<section class="info-box fail"> | |
<ul> | |
@foreach($errors->all() as $error) | |
<li>{{ $error }}</li> | |
@endforeach | |
</ul> | |
</section> | |
@endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\Post; | |
class PostController extends Controller{ | |
public function getBlogIndex() { | |
return view('front-end.blog.index'); | |
} | |
public function getSinglePost($post_id, $end='front-end') { | |
return view($end . '.blog.post'); | |
} | |
public function getCreatePost() { | |
return view('admin.blog.create_post'); | |
} | |
public function postCreatePost(Request $request){ | |
$this->validate($request, [ | |
'title' => 'required|max:120|unique:posts', | |
'author' => 'required|max:80', | |
'body' => 'required' | |
]); | |
$post = new Post(); | |
$post->title = $request['title']; | |
$post->author = $request['author']; | |
$post->body = $request['body']; | |
$post->save(); | |
return redirect()->route('admin.index')->with(['success' => 'Post criado com sucesso!']); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::group(['middleware' => ['web']], function(){ | |
Route::group(['prefix' => '/admin'], function(){ | |
Route::get('/', [ | |
'uses' => 'AdminController@getIndex', | |
'as' => 'admin.index' | |
]); | |
Route::get('/blog/posts/create', [ | |
'uses' => 'PostController@getCreatePost', | |
'as' => 'admin.blog.create_post' | |
]); | |
Route::post('/blog/post/create', [ | |
'uses' => 'PostController@postCreatePost', | |
'as' => 'admin.blog.post.create' | |
]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment