Ajoute la page de listing public

This commit is contained in:
Clement 2020-09-04 09:44:27 +02:00
parent 671ae11e88
commit ad682460e2
12 changed files with 260 additions and 2 deletions

View File

@ -4,10 +4,13 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;
use Spatie\QueryBuilder\QueryBuilder;
class Home extends Model
class Home extends Model implements Feedable
{
protected $fillable = [
'title', 'price', 'surface', 'garden_surface', 'rooms', 'energy',
@ -66,4 +69,24 @@ class Home extends Model
Artisan::call('app:downloadimage ' . $home->id);
});
}
/**
* @inheritDoc
*/
public function toFeedItem()
{
return FeedItem::create()
->id($this->id)
->title($this->title)
->summary($this->excerpt())
->author('Shikiryu')
->updated($this->created_at)
->link(\route('public.view', ['slug' => $this->slug]))
;
}
public static function getFeedItems()
{
return self::where('slug', '!=', null)->limit(20)->get();
}
}

View File

@ -26,4 +26,14 @@ class PublicController extends Controller
return view('public.view', ['home' => $home]);
}
public function list()
{
$homes = Home::where('slug', '!=', null)->paginate(12);
$this->seo()
->setTitle('Liste des maisons rêvées')
->setDescription('La sélection');
return view('public.list', ['homes' => $homes]);
}
}

View File

@ -20,6 +20,7 @@
"laravel/framework": "^7.0",
"laravel/tinker": "^2.0",
"laravel/ui": "^2.1",
"spatie/laravel-feed": "^2.7",
"spatie/laravel-query-builder": "^2.8"
},
"require-dev": {

80
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b1bb2469deb87a0a1452b8b376e64e1a",
"content-hash": "f2c45183934d3f7aaed61cff5cbff385",
"packages": [
{
"name": "absmoca/leboncoin",
@ -2301,6 +2301,84 @@
],
"time": "2020-03-29T20:13:32+00:00"
},
{
"name": "spatie/laravel-feed",
"version": "2.7.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-feed.git",
"reference": "287991a339b98274df56098fa4249afa3ac26211"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-feed/zipball/287991a339b98274df56098fa4249afa3ac26211",
"reference": "287991a339b98274df56098fa4249afa3ac26211",
"shasum": ""
},
"require": {
"illuminate/contracts": "~5.8.0|^6.0|^7.0",
"illuminate/http": "~5.8.0|^6.0|^7.0",
"illuminate/support": "~5.8.0|^6.0|^7.0",
"php": "^7.2"
},
"require-dev": {
"orchestra/testbench": "~3.8.0|^4.0|^5.0",
"phpunit/phpunit": "^8.0",
"spatie/phpunit-snapshot-assertions": "^2.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Spatie\\Feed\\FeedServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Spatie\\Feed\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jolita Grazyte",
"email": "jolita@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
},
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
},
{
"name": "Sebastian De Deyne",
"email": "sebastian@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "Generates rss feed",
"homepage": "https://github.com/spatie/laravel-feed",
"keywords": [
"laravel",
"laravel-feed",
"rss",
"spatie"
],
"funding": [
{
"url": "https://spatie.be/open-source/support-us",
"type": "custom"
}
],
"time": "2020-06-11T22:56:36+00:00"
},
{
"name": "spatie/laravel-query-builder",
"version": "2.8.2",

36
config/feed.php Normal file
View File

@ -0,0 +1,36 @@
<?php
return [
'feeds' => [
'main' => [
/*
* Here you can specify which class and method will return
* the items that should appear in the feed. For example:
* 'App\Model@getAllFeedItems'
*
* You can also pass an argument to that method:
* ['App\Model@getAllFeedItems', 'argument']
*/
'items' => 'App\Home@getFeedItems',
/*
* The feed will be available on this url.
*/
'url' => '/feed',
'title' => 'Les maisons de Bretagne',
'description' => 'La sélection',
'language' => 'fr-FR',
/*
* The view that will render the feed.
*/
'view' => 'feed::atom',
/*
* The type to be used in the <link> tag
*/
'type' => 'application/atom+xml',
],
],
];

View File

@ -6,6 +6,7 @@
@if(Auth::guest())
{!! SEO::generate() !!}
@include('feed::links')
@endif
<!-- CSRF Token -->

View File

@ -0,0 +1,39 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-header">{{ __('List') }}</div>
<div class="card-body">
<div class="row">
@if(count($homes) > 0)
@foreach($homes as $home)
<div class="col-sm-4">
<div class="card">
<img class="card-img-top" src="{{ asset($home->pictures[0]) }}">
<div class="card-body">
<h5 class="card-title">
{{ $home->title }}
<small class="badge badge-@if($home->price <= 100000)primary @elseif($home->price <= 200000)success @else()warning @endif">{{ Str::currency($home->price) }}</small>
</h5>
<p class="card-text">{{ $home->excerpt() }}</p>
<a href="{{ route('public.view', ['slug' => $home->slug]) }}" class="btn btn-primary">Voir la maison</a>
</div>
</div>
</div>
@endforeach
<div class="col-sm-12 mt-4">
{{ $homes->links() }}
</div>
@else
Aucune maison publique :(
@endif
</div>
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@ -0,0 +1,37 @@
<?=
/* Using an echo tag here so the `<? ... ?>` won't get parsed as short tags */
'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
?>
<feed xmlns="http://www.w3.org/2005/Atom">
@foreach($meta as $key => $metaItem)
@if($key === 'link')
<{{ $key }} href="{{ url($metaItem) }}"></{{ $key }}>
@elseif($key === 'title')
<{{ $key }}><![CDATA[{{ $metaItem }}]]></{{ $key }}>
@else
<{{ $key }}>{{ $metaItem }}</{{ $key }}>
@endif
@endforeach
@foreach($items as $item)
<entry>
<title><![CDATA[{{ $item->title }}]]></title>
<link rel="alternate" href="{{ url($item->link) }}" />
<id>{{ url($item->id) }}</id>
<author>
<name> <![CDATA[{{ $item->author }}]]></name>
</author>
<summary type="html">
<![CDATA[{!! $item->summary !!}]]>
</summary>
@if($item->__isset('enclosure'))
<enclosure url="{{ url($item->enclosure) }}" length="{{ $item->enclosureLength }}" type="{{ $item->enclosureType }}" />
@endif
@foreach($item->category as $category)
<category type="html">
<![CDATA[{!! $category !!}]]>
</category>
@endforeach
<updated>{{ $item->updated->toRssString() }}</updated>
</entry>
@endforeach
</feed>

View File

@ -0,0 +1 @@
@include('feed::atom')

View File

@ -0,0 +1,3 @@
@foreach($feeds as $name => $feed)
<link rel="alternate" type="{{ $feed['type'] ?? 'application/atom+xml' }}" href="{{ route("feeds.{$name}") }}" title="{{ $feed['title'] }}">
@endforeach

View File

@ -0,0 +1,27 @@
<?=
/* Using an echo tag here so the `<? ... ?>` won't get parsed as short tags */
'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
?>
<rss version="2.0">
<channel>
<title><![CDATA[{{ $meta['title'] }}]]></title>
<link><![CDATA[{{ url($meta['link']) }}]]></link>
<description><![CDATA[{{ $meta['description'] }}]]></description>
<language>{{ $meta['language'] }}</language>
<pubDate>{{ $meta['updated'] }}</pubDate>
@foreach($items as $item)
<item>
<title><![CDATA[{{ $item->title }}]]></title>
<link>{{ url($item->link) }}</link>
<description><![CDATA[{!! $item->summary !!}]]></description>
<author><![CDATA[{{ $item->author }}]]></author>
<guid>{{ url($item->id) }}</guid>
<pubDate>{{ $item->updated->toRssString() }}</pubDate>
@foreach($item->category as $category)
<category>{{ $category }}</category>
@endforeach
</item>
@endforeach
</channel>
</rss>

View File

@ -22,11 +22,13 @@ Route::get('/', static function () {
});
Auth::routes(['register' => false]);
Route::feeds();
Route::get('/home', static function () {
if (Auth::guest()) {
return redirect(\route('login'));
}
});
Route::get('/list', 'PublicController@list')->name('public.list');
Route::get('/{slug}', 'PublicController@show')->name('public.view');