Installation
To create a new App with Slice, just run the command below.
composer create-project -s dev cupoftea/slice "Your App Path"
Usage
Using Slice is a super simple. Just define your routes in routes/web.php
or routes/api.php
, and start creating your views in resources/views
. Slice will take care of the rest.
routes/web.php
<?php
$router->view('/', 'home')->name('home');
$router->view('about', 'about')->name('about');
resources/views/home.blade.php
@extends('layouts.master')
@section('content')
<div class="container">
<h1>Hello World</h1>
<p class="lead">Welcome to my app!</p>
</div>
@endsection
resources/views/about.blade.php
@extends('layouts.master')
@section('content')
<div class="container">
<h1>About My App</h1>
<p class="lead">I made this all by myself!</p>
</div>
@endsection
resources/views/layouts/master.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" id="Slice">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ config('app.name', 'My App') }}</title>
<!-- Fonts -->
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,400i,700" rel="stylesheet">
<!-- Styles -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body class="route-{{ app('router')->currentRouteName() }}">
<div id="app">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="/">My App</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item {{ app('router')->currentRouteName() == 'home' ? 'active' : '' }}">
<a class="nav-link" href="{{ route('home') }}">
Home
@if(app('router')->currentRouteName() == 'home')<span class="sr-only">(current)</span>@endif
</a>
</li>
<li class="nav-item {{ app('router')->currentRouteName() == 'about' ? 'active' : '' }}">
<a class="nav-link" href="{{ route('about') }}">
About
@if(app('router')->currentRouteName() == 'about')<span class="sr-only">(current)</span>@endif
</a>
</li>
</ul>
</div>
</nav>
@yield('content')
</div>
</body>
</html>
Helpers
Slice has a bunch of useful helpers you'll probably recognise from Laravel. In addition, all helpers from illuminate/support
are also available to you.
-
Get the Slice Application.app()
-
See the Laravel Documentation for more info.abort()
-
See the Laravel Documentation for more info.abort_if()
-
See the Laravel Documentation for more info.abort_unless()
-
See the Laravel Documentation for more info.back()
-
See the Laravel Documentation for more info.base_path()
-
See the Laravel Documentation for more info.config()
-
See the Laravel Documentation for more info.config_path()
-
See the Laravel Documentation for more info.method_field()
-
See the Laravel Documentation for more info.now()
-
See the Laravel Documentation for more info.old()
-
See the Laravel Documentation for more info.public_path()
-
See the Laravel Documentation for more info.redirect()
-
See the Laravel Documentation for more info.request()
-
See the Laravel Documentation for more info.rescue()
-
See the Laravel Documentation for more info.resource_path()
-
See the Laravel Documentation for more info.response()
-
See the Laravel Documentation for more info.route()
-
See the Laravel Documentation for more info.storage_path()
-
See the Laravel Documentation for more info.today()
-
See the Laravel Documentation for more info.url()
-
See the Laravel Documentation for more info.view()