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/ */

    

sureshmayanglambam / surexcore example snippets


$routes->get('news', [News::class, 'index'], ['as' => 'news']);
$routes->get('news/(:segment)', [News::class, 'detail'], ['as' => 'news.detail']);

class NewsModel extends EntryModel
{
    protected string $contentTypeSlug = 'news';
}

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

$routes->get('about', [Page::class, 'show'], ['as' => 'about']);              // View/frontend/about.blade.php (or about/index.blade.php)
$routes->get('company/access', [Page::class, 'show'], ['as' => 'company.access']);

protected array $fields = [
    'email' => ['label' => 'メールアドレス', 'rules' => 'th[100]'],
];

model(InquiryModel::class)->store('recruit', ['お名前' => $name, …], $name, $email, $attachment);
bash
docker compose exec app php spark routes
docker compose exec app php spark migrate:status
bash
php spark db:seed NewsSample
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 --}}

From: {{ $fromName }} <{{ $fromEmail }}>
Reply-To: {{ $data['email'] }}
Cc:
Bcc:
Subject: 【{{ $siteName }}】お問い合わせがありました

本文…