*/
class AdCampaign extends Model implements Sortable, PillBoxContract
{
- use HasSlug, HasMedias, HasPosition;
+ use HasSlug, HasMedias, HasPosition, HasSubscriberOnlyContent;
use Searchable;
protected $fillable = [
'box_title',
'box_content',
'box_link',
+ 'subscriber_only'
];
public $appends = [
trait HasSubscriberOnlyContent
{
+ protected int $maxContentWords = 100;
+
/**
* @return string
* @throws InvalidHtmlException
*/
public function getTruncatedContent(): string
{
- return Truncator::truncate($this->content, 100);
+ return Truncator::truncate($this->content, $this->maxContentWords);
}
- /**
- * @param User|null $user
- * @return bool
- */
- public function isVisibleByUser(User $user = null)
- {
- $user ??= \Auth::user();
-
- return !$this->subscriber_only ||
- ($user !== null && $user->hasValidSubscription());
-
- }
}
*/
class LaboArticle extends Model implements Sortable, PillBoxContract
{
- use HasSlug, HasMedias, HasPosition;
+ use HasSlug, HasMedias, HasPosition, HasSubscriberOnlyContent;
protected $fillable = [
'publish_start_date',
'box_title',
'box_content',
'box_link',
+ 'subscriber_only'
];
public $slugAttributes = [
--- /dev/null
+<?php
+
+namespace App\Policies;
+
+use App\Models\AdCampaign;
+use App\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class AdCampaignPolicy
+{
+ use HandlesAuthorization;
+
+ /**
+ * Determine whether the user can view any models.
+ *
+ * @param \App\User $user
+ * @return mixed
+ */
+ public function viewAny(User $user)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can view the model.
+ *
+ * @param null|\App\User $user
+ * @param \App\Models\AdCampaign $adCampaign
+ * @return mixed
+ */
+ public function view(?User $user, AdCampaign $adCampaign)
+ {
+ return !$adCampaign->subscriber_only ||
+ optional($user)->hasValidSubscription();
+ }
+
+ /**
+ * Determine whether the user can create models.
+ *
+ * @param \App\User $user
+ * @return mixed
+ */
+ public function create(User $user)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can update the model.
+ *
+ * @param \App\User $user
+ * @param \App\Models\AdCampaign $adCampaign
+ * @return mixed
+ */
+ public function update(User $user, AdCampaign $adCampaign)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can delete the model.
+ *
+ * @param \App\User $user
+ * @param \App\Models\AdCampaign $adCampaign
+ * @return mixed
+ */
+ public function delete(User $user, AdCampaign $adCampaign)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can restore the model.
+ *
+ * @param \App\User $user
+ * @param \App\Models\AdCampaign $adCampaign
+ * @return mixed
+ */
+ public function restore(User $user, AdCampaign $adCampaign)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can permanently delete the model.
+ *
+ * @param \App\User $user
+ * @param \App\Models\AdCampaign $adCampaign
+ * @return mixed
+ */
+ public function forceDelete(User $user, AdCampaign $adCampaign)
+ {
+ //
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Policies;
+
+use App\Models\LaboArticle;
+use App\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class LaboArticlePolicy
+{
+ use HandlesAuthorization;
+
+ /**
+ * Determine whether the user can view any models.
+ *
+ * @param \App\User $user
+ * @return mixed
+ */
+ public function viewAny(User $user)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can view the model.
+ *
+ * @param null|\App\User $user
+ * @param \App\Models\LaboArticle $laboArticle
+ * @return mixed
+ */
+ public function view(?User $user, LaboArticle $laboArticle)
+ {
+ return !$laboArticle->subscriber_only ||
+ optional($user)->hasValidSubscription();
+ }
+
+ /**
+ * Determine whether the user can create models.
+ *
+ * @param \App\User $user
+ * @return mixed
+ */
+ public function create(User $user)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can update the model.
+ *
+ * @param \App\User $user
+ * @param \App\Models\LaboArticle $laboArticle
+ * @return mixed
+ */
+ public function update(User $user, LaboArticle $laboArticle)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can delete the model.
+ *
+ * @param \App\User $user
+ * @param \App\Models\LaboArticle $laboArticle
+ * @return mixed
+ */
+ public function delete(User $user, LaboArticle $laboArticle)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can restore the model.
+ *
+ * @param \App\User $user
+ * @param \App\Models\LaboArticle $laboArticle
+ * @return mixed
+ */
+ public function restore(User $user, LaboArticle $laboArticle)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can permanently delete the model.
+ *
+ * @param \App\User $user
+ * @param \App\Models\LaboArticle $laboArticle
+ * @return mixed
+ */
+ public function forceDelete(User $user, LaboArticle $laboArticle)
+ {
+ //
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Policies;
+
+use App\Models\SocialArticle;
+use App\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class SocialArticlePolicy
+{
+ use HandlesAuthorization;
+
+ /**
+ * Determine whether the user can view any models.
+ *
+ * @param User $user
+ * @return mixed
+ */
+ public function viewAny(User $user)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can view the model.
+ *
+ * @param User|null $user
+ * @param \App\Models\SocialArticle $socialArticle
+ * @return mixed
+ */
+ public function view(?User $user, SocialArticle $socialArticle)
+ {
+ return !$socialArticle->subscriber_only ||
+ optional($user)->hasValidSubscription();
+ }
+
+ /**
+ * Determine whether the user can create models.
+ *
+ * @param User $user
+ * @return mixed
+ */
+ public function create(User $user)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can update the model.
+ *
+ * @param User $user
+ * @param \App\Models\SocialArticle $socialArticle
+ * @return mixed
+ */
+ public function update(User $user, SocialArticle $socialArticle)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can delete the model.
+ *
+ * @param User $user
+ * @param \App\Models\SocialArticle $socialArticle
+ * @return mixed
+ */
+ public function delete(User $user, SocialArticle $socialArticle)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can restore the model.
+ *
+ * @param User $user
+ * @param \App\Models\SocialArticle $socialArticle
+ * @return mixed
+ */
+ public function restore(User $user, SocialArticle $socialArticle)
+ {
+ //
+ }
+
+ /**
+ * Determine whether the user can permanently delete the model.
+ *
+ * @param User $user
+ * @param \App\Models\SocialArticle $socialArticle
+ * @return mixed
+ */
+ public function forceDelete(User $user, SocialArticle $socialArticle)
+ {
+ //
+ }
+}
namespace App\Providers;
+
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
* @var array
*/
protected $policies = [
- // 'App\Model' => 'App\Policies\ModelPolicy',
+ \App\Models\SocialArticle::class => \App\Policies\SocialArticlePolicy::class,
+ \App\Models\LaboArticle::class => \App\Policies\LaboArticlePolicy::class,
+ \App\Models\AdCampaign::class => \App\Policies\AdCampaignPolicy::class,
];
/**
--- /dev/null
+<?php
+
+namespace App\View\Components;
+
+use App\Models\HasSubscriberOnlyContent;
+use Illuminate\View\Component;
+
+class SubscriberOnlyContent extends Component
+{
+
+
+ public $article;
+
+ /**
+ * Create a new component instance.
+ *
+ * @param $article
+ * @throws \RuntimeException
+ */
+ public function __construct($article)
+ {
+ throw_unless(
+ in_array(HasSubscriberOnlyContent::class, class_uses($article), true),
+ new \RuntimeException("The article must implement HasSubscriberOnly trait")
+ );
+
+
+ $this->article = $article;
+ }
+
+ /**
+ * Get the view / contents that represent the component.
+ *
+ * @return \Illuminate\View\View|string
+ */
+ public function render()
+ {
+ return view('components.subscriber-only-content');
+ }
+}
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddSubscriberOnlyToLaboArticles extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('labo_articles', function (Blueprint $table) {
+ $table->boolean('subscriber_only')->default(0);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('labo_articles', function (Blueprint $table) {
+ $table->dropColumn('subscriber_only');
+ });
+ }
+}
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddSubscriberOnlyToAdCampaigns extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('ad_campaigns', function (Blueprint $table) {
+ $table->boolean('subscriber_only')->default(0);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('ad_campaigns', function (Blueprint $table) {
+ $table->dropColumn('subscriber_only');
+ });
+ }
+}
{{-- <h2>{{$actu->title}}</h2>--}}
{{-- <div class="chapo">{{$actu->chapo}}</div>--}}
<div class="content ck-content">
- {!! $actu->content !!}
+ <x-subscriber-only-content :article="$actu"></x-subscriber-only-content>
</div>
'label' => 'Image',
])
+ @formField('radios', [
+ 'name' => 'subscriber_only',
+ 'label' => 'Article réservé aux abonnés',
+ 'default' => false,
+ 'inline' => true,
+ 'options' => [
+ [
+ 'value' => false,
+ 'label' => 'Non'
+ ],
+ [
+ 'value' => true,
+ 'label' => 'Oui'
+ ],
+ ]
+ ])
+
@formField('ckeditor', [
'name' => 'content',
'label' => 'Article complet',
])
+ @formField('radios', [
+ 'name' => 'subscriber_only',
+ 'label' => 'Article réservé aux abonnés',
+ 'default' => false,
+ 'inline' => true,
+ 'options' => [
+ [
+ 'value' => false,
+ 'label' => 'Non'
+ ],
+ [
+ 'value' => true,
+ 'label' => 'Oui'
+ ],
+ ]
+ ])
+
@formField('ckeditor', [
'label' => 'Article complet',
'name' => 'content',
</div>
<div class="col-sm-8">
<div class="content ck-content">
- {!! $campaign->content !!}
+ <x-subscriber-only-content :article="$campaign"></x-subscriber-only-content>
</div>
</div>
</div>
--- /dev/null
+<div>
+ @can('view', $article)
+ {!! $article->content !!}
+ @else
+ <div class="truncated clearfix">
+ {!! $article->getTruncatedContent() !!}
+ </div>
+ <div class="alert alert-warning mt-4">
+ Cet article est réservé aux abonnés ! Pour y accéder merci de vous connecter, ou
+ <a href="{{route('not-registered')}}" >cliquez ici pour découvrir nos formules d'abonnement.</a>
+ </div>
+ @endif
+
+</div>
@section('content')
- <article class="container">
+ <div class="container">
<div class="row">
<div class="col-sm-4">
<x-pill-box slug="article-reseaux-sociaux" :object="$article" class="mb-4"></x-pill-box>
</div>
- <div class="col-sm-8">
+ <article class="col-sm-8">
<h2>{{$article->title}}</h2>
<div class="chapo">{!! $article->chapo !!}</div>
- <div class="content ck-content mt-5">
- @if($article->isVisibleByUser())
- {!! $article->content !!}
- @else
- <div class="truncated">
- {!! $article->getTruncatedContent() !!}
- </div>
- <div class="alert alert-warning mt-4">
- Cet article est réservé aux abonnés ! Pour y accéder merci de vous connecter, ou
- <a href="{{route('not-registered')}}" >cliquez ici pour découvrir nos formules d'abonnement.</a>
- </div>
- @endif
+ <div class="content ck-content mt-5">
+ <x-subscriber-only-content :article="$article"></x-subscriber-only-content>
</div>
- </div>
+ </article>
</div>
- </article>
+ </div>
@endsection