Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions app/Admin/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Admin\Controllers;

use App\Models\Category;
use App\Models\Menu;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
Expand Down Expand Up @@ -77,6 +78,13 @@ protected function form()
$form->slug = Str::slug($form->name);
});

$form->saved(function ($form) {
$menu = new Menu();
$menu->display_name = $form->name;
$menu->url = '/category/' . $form->slug;
$menu->save();
});

return $form;
}
}
75 changes: 75 additions & 0 deletions app/Admin/Controllers/MenuController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Admin\Controllers;

use App\Models\Menu;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class MenuController extends AdminController
{
/**
* Title for current resource.
*
* @var string
*/
protected $title = 'Menu';

/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$grid = new Grid(new Menu());

$grid->column('id', __('Id'));
$grid->column('display_name', __('Display name'));
$grid->column('url', __('Url'));
$grid->column('child', __('Child'));
$grid->column('created_at', __('Created at'));
$grid->column('updated_at', __('Updated at'));

return $grid;
}

/**
* Make a show builder.
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
$show = new Show(Menu::findOrFail($id));

$show->field('id', __('Id'));
$show->field('display_name', __('Display name'));
$show->field('url', __('Url'));
$show->field('child', __('Child'));
$show->field('created_at', __('Created at'));
$show->field('updated_at', __('Updated at'));

return $show;
}

/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
$form = new Form(new Menu());

$form->text('display_name', __('Display name'));
$form->text('url', __('Url'));
$form->text('child', __('Child'));
$form->number('order');

return $form;
}
}
1 change: 1 addition & 0 deletions app/Admin/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
$router->resource('posts', PostController::class);
$router->resource('static-contents', StaticContentController::class);
$router->resource('contact-messages', ContactMsgController::class);
$router->resource('menus', MenuController::class);
});
12 changes: 6 additions & 6 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace App\Http\Controllers;

use App\Models\Post;
use Illuminate\Http\Request;
use App\Models\Menu;
use App\Models\StaticContent;

class HomeController extends Controller
{
public function index()
{

$menuTab = Menu::orderBy('order', 'desc')->get();
$staticContent = StaticContent::where('status', 'index')->get();
return view('index', [
'posts' => json_encode(Post::where('status', 'publish')
->orderBy('id', 'desc')
->paginate(10))
'menuTab' => json_encode($menuTab),
'staticContent' => json_encode($staticContent)
]);
}
}
17 changes: 16 additions & 1 deletion app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@

namespace App\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Models\Post;

class PostController extends Controller
{
public function getListPosts()
public function getListPosts(): JsonResponse
{
return response()->json(Post::where('status', 'publish')
->with('categories:name,slug,status', 'tags:name,slug,status')
->orderBy('id', 'desc')
->paginate(10));
}

public function getListPostsByCat($category): JsonResponse
{
return response()->json(
Post::where('status', 'publish')
->whereHas('categories', function ($query) use ($category) {
$query->where('slug', $category);
})
->with('categories:name,slug,status', 'tags:name,slug,status')
->orderBy('id', 'desc')
->paginate(10)
);
}
}
8 changes: 8 additions & 0 deletions app/Repo/PostRepo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php


namespace App\Repo;

class PostRepo
{
}
87 changes: 87 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/sh

projectName=$(basename -s .git `git config --get remote.origin.url`)
replace=""
projectName=${projectName//sw-shop-/$replace}

# Ask the user for the database user
read -p "$(tput setaf 2)Enter you root database user $(tput setaf 3)[root]$(tput sgr0): " dbUser
dbUser=${dbUser:-root}

# Ask the user for the database password
echo -n "$(tput setaf 2)Enter you root database password $(tput setaf 3)[root]$(tput sgr0): ":
read -s dbPassword
dbPassword=${dbPassword:-root}

mysql -u $dbUser -p$dbPassword -e "CREATE DATABASE IF NOT EXISTS $projectName;"

mysql -u $dbUser -p$dbPassword $projectName < "./database/$projectName.sql"

cp .env.init .env
# setup the environment
sed -i "" -e "s%APP_URL=http://127.0.0.1:8000%APP_URL=http://$projectName.local%" .env
sed -i "" -e "s%DATABASE_URL=mysql://root:root@localhost/shopware%DATABASE_URL=mysql://$dbUser:$dbPassword@localhost:3306/$projectName%" .env

# install shopware and dependencies according to the composer.lock
composer install --no-interaction --optimize-autoloader
composer require deployer/deployer

sed -i "" -e "s%APP_SECRET=APP_SECRET%APP_SECRET=$(php artisan key:generate)%" .env

# create database with a basic setup (admin user and storefront sales channel)
bin/console system:install --create-database --basic-setup

echo "$(tput setaf 2)Select the server you are using on you local machine:$(tput setaf 3)\n\t[0]$(tput setaf 2)Apache\n\t$(tput setaf 3)[1]$(tput setaf 2)Ngnix$(tput sgr0)"
read server
if [ "$server" == "1" ]; then
echo "You selected Ngnix"
read -p "$(tput setaf 2)Enter path to virtual host config directory $(tput setaf 3)[/opt/homebrew/etc/nginx/vhosts]$(tput sgr0): " directory
directory=${directory:-/opt/homebrew/etc/nginx/vhosts}
path="${directory}/${projectName}.local.conf"
echo "server {" > $path
echo " listen 80;" >> $path
echo " index index.php;" >> $path
echo " server_name $projectName.local;" >> $path
echo " root $PWD/public;" >> $path
echo " location / {" >> $path
echo " try_files \$uri /index.php\$is_args\$args;" >> $path
echo " }" >> $path
echo " location ~ \.php$ {" >> $path
echo " fastcgi_split_path_info ^(.+\.php)(/.+)$;" >> $path
echo " include fastcgi.conf;" >> $path
echo " fastcgi_buffers 8 16k;" >> $path
echo " fastcgi_buffer_size 32k;" >> $path
echo " fastcgi_read_timeout 300s;" >> $path
echo " client_body_buffer_size 128k;" >> $path
echo " http2_push_preload on;" >> $path
echo " fastcgi_pass 127.0.0.1:9000;" >> $path
echo " fastcgi_index index.php;" >> $path
echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;" >> $path
echo " include fastcgi_params;" >> $path
echo " }" >> $path
echo "}" >> $path
echo "Enter you sudo password:"
sudo -- sh -c "echo \"\n127.0.0.1\t${projectName}.local\" >> /private/etc/hosts"
sudo -- sh -c "echo \"::1 \t${projectName}.local\" >> /private/etc/hosts"
brew services restart nginx
else
echo "You selected Apache"
read -p "$(tput setaf 2)Enter path to virtual host config directory $(tput setaf 3)[/opt/homebrew/etc/httpd/vhosts]$(tput sgr0): " directory
directory=${directory:-/opt/homebrew/etc/httpd/vhosts}
path="${directory}/${projectName}.local.conf"
echo "<VirtualHost *:80>" > $path
echo " ServerName ${projectName}.local" >> $path
echo " DocumentRoot $PWD/public/" >> $path
echo " <Directory $PWD>" >> $path
echo " Options Indexes FollowSymLinks MultiViews Includes execCGI " >> $path
echo " AllowOverride All" >> $path
echo " Require all granted" >> $path
echo " </Directory>" >> $path
echo "</VirtualHost>" >> $path
echo "Enter you sudo password:"
sudo -- sh -c "echo \"\n127.0.0.1\t${projectName}.local\" >> /private/etc/hosts"
sudo -- sh -c "echo \"::1 \t${projectName}.local\" >> /private/etc/hosts"
brew services restart httpd
fi
echo "Project initialized with virtual host: http://${projectName}.local"
open http://${projectName}.local
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"laravel/tinker": "^2.5"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.7",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
Expand Down
Loading