<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\Http\Controllers\PostController;
use Illuminate\Support\Facades\DB;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    $setting = config('settings');

    $posts = DB::select('select * from posts limit 7');
    $setting['posts'] = $posts;

    return view('index', $setting);
});

Route::get('/post/{id}', function ($id) {
    $setting = config('settings');

    $posts = DB::select('select * from posts where id=?', [$id]);
    $setting['posts'] = $posts;

    return view('post', $setting);
});

Route::get('/login', function () {
    if(session('user')){
        return view('admin/index', config('settings'));
    }
    return view('login', config('settings'));
});

Route::post('/login', [UserController::class, 'checkUser']);

Route::post('/admin/post', [PostController::class, 'insertPost']);

 

<!--resources/views/index.balde.php-->
@include('partials.header')
<link href="{{ asset('styles/index.css') }}" rel='stylesheet' />

<div class='Main'>
@foreach ($posts as $post)
<div class='item'>
    <a href="<?php echo url('/post') ?>/{{ $post->id }}">
        <img class='thumb' src="{{ $post->thumb }}" />
    </a>
    <div class="title">
        <a href="<?php echo url('/post') ?>/{{ $post->id }}">
        {{ $post->title }}
        </a>
        <div>
        <script>
            var date = new Date('{{ $post->created_at }}')
            document.write(date.toLocaleDateString())
        </script>
        </div>
    </div>
</div>
@endforeach
</div>

@include('partials.footer')

 

.Main{
    margin-top: 30px;
}
.Main .item{
    display: grid;
    grid-template-columns: 30% auto;
    grid-gap: 20px;
    padding-bottom: 20px;
}

.Main .item a{
    width: 100%;
}

.Main .item a img{
    width: 100%;
    float: left;
}

.Main .item .title a{
    font: 18px/1.5 Oswald, Limonf3;
}

 

GitHub: https://github.com/Sokhavuth/laravel

Heroku: http://khmerweb-laravel.herokuapp.com/