PHP code example of sureshmayanglambam / surexcore
1. Go to this page and download the library: Download sureshmayanglambam/surexcore library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
public function index(): string
{
$posts = NewsModel::published()->latest()->paginate(10);
return $this->render('frontend.news.index', compact('posts'));
}
public function detail(string $slug): string
{
$post = NewsModel::published()->where('slug', $slug)->firstOrFail();
return $this->render('frontend.news.detail', compact('post'));
}
NewsModel::published()->latest()->paginate(10); // + {!! pagination() !!} in the view
NewsModel::published()->where('news_type', 'event')->latest()->limit(3)->get();
NewsModel::published()->whereJsonContains('news_category', 'company')->get(); // checkbox / relation fields
NewsModel::published()->where('slug', $slug)->firstOrFail(); // 404 when not found
NewsModel::query()->where('status', 'draft')->oldest()->get(); // all entries incl. drafts
NewsModel::query()->findOrFail($id);
entries('store')->where('price <', 1000)->orderBy('price')->paginate(12); // published only
entry('store', $slug); // one published entry or null
content_type_exists('store');
NewsModel::published()->whereJsonContains('shop', 5)->get(); // entries linked to entry 5
blade
{{ $post->news_title }} {{-- text --}}
{!! nl2br(esc($post->news_summary)) !!} {{-- textarea: escaped, line breaks kept --}}
{{ $post->label('news_type') }} {{-- radio / select: label of the stored value --}}
@foreach($post->label('news_category') as $c) … @endforeach {{-- checkbox: list of labels --}}
@if($post->news_pickup) … @endif {{-- on/off: true / false --}}
<img src="{{ media_url($post->news_image) }}"> {{-- image --}}
<div class="ck-content">{!! $post->news_detail !!}</div> {{-- CKEditor: trusted HTML --}}
@foreach($post->field('news_links', []) as $link) {{-- repeater: rows as arrays --}}
<a href="{{ $link['link_url'] }}">{{ $link['link_label'] }}</a>
@endforeach
@foreach($post->relation('news_related') as $related) {{-- relation: linked entries (published) --}}
<a href="{{ url_to('news.detail', $related->slug) }}">{{ $related->title }}</a>
@endforeach
bash
php spark make:cms-model Store # App/Model/StoreModel.php — content type slug "store"
php spark make:cms-controller Store # App/Controller/Store.php — uses StoreModel, empty index() / detail()
blade
{{ $post->relation('shop')?->title }} {{-- single → Entry or null --}}
@foreach($post->relation('tags') as $tag) … @endforeach {{-- multiple → list of entries --}}