Ajoute les liens publics

This commit is contained in:
Clement 2020-07-24 13:11:21 +02:00
parent 2decec3fab
commit b349420bec
7 changed files with 152 additions and 5 deletions

View File

@ -0,0 +1,14 @@
<?php
namespace App\Http\Controllers;
use App\Home;
class PublicController extends Controller
{
public function show($slug)
{
$home = Home::where('slug', $slug)->firstOrFail();
return view('public.view', ['home' => $home]);
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class UpdateHomesWithPublicUuid extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('homes', static function (Blueprint $table) {
$table->string('slug')->nullable()->comment('Uuid for public link');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('homes', static function (Blueprint $table) {
$table->dropColumn('slug');
});
}
}

View File

@ -96,6 +96,16 @@
</select>
</div>
</div>
<div class="col-lg-4">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="slug" id="slug-non" value="" checked>
<label class="form-check-label" for="slug-non">Non</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="slug" id="slug-oui" value="{{ \Illuminate\Support\Str::uuid() }}">
<label class="form-check-label" for="slug-oui">Oui</label>
</div>
</div>
<div class="col-lg-4">
<button type="submit" class="btn btn-primary">Submit</button>
</div>

View File

@ -99,6 +99,16 @@
</select>
</div>
</div>
<div class="col-lg-4">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="slug" id="slug-non" value="" @if(empty($home->slug)) checked @endif>
<label class="form-check-label" for="slug-non">Non</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="slug" id="slug-oui" @if(!empty($home->slug)) checked @endif value="@if(!empty($home->slug)) {{ $home->slug }} @else {{ \Illuminate\Support\Str::uuid() }} @endif">
<label class="form-check-label" for="slug-oui">Oui</label>
</div>
</div>
<div class="col-lg-4">
<button type="submit" class="btn btn-primary">Submit</button>
</div>

View File

@ -67,7 +67,8 @@
<div class="col-lg-3"><strong>GES : </strong> {{ $home->ges ?? '' }}</div>
</div>
<div class="row">
<div class="col-lg-3 offset-5"><a href="{{ route('home.update', $home->id) }}" class="btn btn-light">Mettre à jour</a></div>
@if(!empty($home->slug)) <div class="col-lg-3"><a href="{{ route('public.view', $home->slug) }}" class="btn btn-light">Lien public</a></div>@endif
<div class="col-lg-3 offset-3"><a href="{{ route('home.update', $home->id) }}" class="btn btn-light">Mettre à jour</a></div>
<div class="col-lg-3"><a href="{{ $home->url }}" class="btn btn-success">Voir l'origine </a></div>
</div>
</div>

View File

@ -0,0 +1,72 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header"><a href="{{ $home->url }}">{{ $home->title }}</a></div>
<div class="card-body">
<div class="row">
<div class="col-lg-12">
<div id="picturesCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
@foreach($home->pictures as $i => $pic)
<li data-target="#picturesCarousel" data-slide-to="{{ $i }}" @if($i === 0)class="active"@endif></li>
@endforeach
</ol>
<div class="carousel-inner">
@foreach($home->pictures as $i => $pic)
<div class="carousel-item @if($i === 0) active @endif">
<img class="d-block w-100" src="{{ asset($pic) }}">
</div>
@endforeach
</div>
<a class="carousel-control-prev" href="#picturesCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#picturesCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
@if(!empty($home->comment))
<div class="card mt-4 mb-4">
<div class="card-header">Mon commentaire</div>
<div class="card-body">
{!! nl2br($home->comment) !!}
</div>
</div>
@endif
<div class="row mb-4">
<div class="col-lg-12">
{!! nl2br($home->description) !!}
</div>
</div>
<div class="row mb-4">
<div class="col-lg-12"><h3>Informations :</h3></div>
<div class="col-lg-3"><strong>Ville : </strong> {{ $home->city }}</div>
<div class="col-lg-3"><strong>Prix : </strong> {{ $home->price }}</div>
<div class="col-lg-3"><strong>Surface : </strong> {{ $home->surface }} </div>
<div class="col-lg-3"><strong>Nombre de pièces : </strong>{{ $home->rooms }}</div>
</div>
<div class="row mb-4">
<div class="col-lg-12"><h3>Informations complémentaires :</h3></div>
<div class="col-lg-3"><strong>Surface de jardin : </strong> {{ $home->garden_surface ?? '' }}</div>
<div class="col-lg-3"><strong>Énergie : </strong> {{ $home->energy ?? '' }}</div>
<div class="col-lg-3"><strong>GES : </strong> {{ $home->ges ?? '' }}</div>
</div>
<div class="row">
<div class="col-lg-3"><a href="{{ $home->url }}" class="btn btn-success">Voir l'origine </a></div>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
/*
@ -13,14 +14,21 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::get('/', function () {
if (\Illuminate\Support\Facades\Auth::guest()) {
return redirect(\route('home'));
Route::get('/', static function () {
if (Auth::guest()) {
return redirect(\route('login'));
}
return redirect(\route('login'));
return redirect(\route('home'));
});
Auth::routes();
Route::get('/home', static function () {
if (Auth::guest()) {
return redirect(\route('login'));
}
});
Route::get('/{slug}', 'PublicController@show')->name('public.view');
Route::group(['middleware' => ['auth']], static function () {
Route::get('/home', 'HomeController@index')->name('home');