BrainCMS V2 [Arcturus EMU / Laravel 5.7 / Boostrap 4.3]

BrainCMS

Brain is live, Live is Brain
Feb 17, 2014
86
32
y3nJWFL.png


Hello DevBest!
My name is Tom, I am the creator of BrainCMS 1.0, I started this project to learn from it,I never thought that so many people would use it! And so I am planning to create a new version to also learn from it.

Current functions
  • Login [100%]
  • Register [80%]
  • Client (Create the SSO in the controller) Need to add online count and full screen button. [50%]
  • Layout [20%]
  • Profiel Page [0%]
  • Staff Page [0%]
  • Hotel Settings [0%]
  • News [0%]
  • Tags [0%]
  • Shops [0%]
  • Admin Panel [0%]
It is not much but it is the start.
Snippers:

Me Controller

PHP:
<?php
namespace App\Http\Controllers\Home;
use Auth;
use App\Http\Controllers\Controller;
class Me extends Controller
{
    public function render ()
    {
        return view('pages.user.home.me', [
            'currency' => Auth::user()->currency
        ]);
    }
}

Client Controller

PHP:
<?php
namespace App\Http\Controllers\Home;
use Auth;
use App\Http\Controllers\Controller;
use Illuminate\Support\Str;
class Client extends Controller
{
    public function render() {
        $sso = $this->generateSSO();
        Auth::user()->update([ "auth_ticket" => $sso ]);
        return view('pages.user.home.client', [ "sso" => $sso ]);
    }
    private function generateSSO() {
        return (string) Str::uuid();
    }
}

Route
PHP:
<?php
Auth::routes();
Route::group([ "middleware" => "guest" ], function () {
    Route::get('/', 'Redirect@render')->name('index');
});
Route::group([ "middleware" => "user" ], function () {
    Route::group([ "namespace" => "Home" ], function () {
        Route::get('me', 'Me@render')->name('me');
        Route::get('client', 'Client@render')->name('client');
        Route::get('logout', 'Logout@render')->name('logout');
    });
});
Screens layout
Index
lAhg8KE.png


Me
d4wXT6c.png

BrainCMS 2.0 on GitHub


Improvements or comments feel free to ask them!

best regards,
Tom
 
Last edited:

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
Thread approved. Good luck with development!

One tip from seeing the screens, as there will be a lot of pages that will need the "auth" middleware, create a route group with the middleware auth in there. That way, you don't have to call it every time in the controller.

Edit: the second tip, put your code on GitHub and actively update it. This way, people can help you along the way, creating pull requests, opening issues or giving you feedback on the forum. It might be a great way to learn new stuff, as people can give continuous tips every time you push your commits.
 

BrainCMS

Brain is live, Live is Brain
Feb 17, 2014
86
32
Thread approved. Good luck with development!

One tip from seeing the screens, as there will be a lot of pages that will need the "auth" middleware, create a route group with the middleware auth in there. That way, you don't have to call it every time in the controller.
Tnx :D

Can you give me an example about the route group?
Lavarvel is quite new to me.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461


PHP:
Route::middleware(['auth'])->group(function () {
    Route::get('/', function () {
        // Uses auth Middleware
    });

    Route::get('user/profile', function () {
        // Uses auth Middleware
    });
});

Now, all routes you place within Route::midleware, will go through the "auth" middleware. You can also create a group from it, but it's just how you prefer to do it. Laravel docs are really good, I'd really recommend giving it a good read-through.
 

BrainCMS

Brain is live, Live is Brain
Feb 17, 2014
86
32


PHP:
Route::middleware(['auth'])->group(function () {
    Route::get('/', function () {
        // Uses first & second Middleware
    });

    Route::get('user/profile', function () {
        // Uses first & second Middleware
    });
});

Now, all routes you place within Route::midleware, will go through the "auth" middleware. You can also create a group from it, but it's just how you prefer to do it. Laravel docs are really good, I'd really recommend giving it a good read-through.
Nice tnx!

I will add it on GitHub

Update:
You must be registered for see images attach
 

LeChris

https://habbo.codes/
Sep 30, 2013
2,786
1,395
Your code is also redundant a bit and there is also no need to directly access the DB from the DB facade if you use Eloquent.

Example would be your client could just simply be
Auth::user()->update([ "sso" => $sso ]);

You also are not using relationships the right way; example on your user model would be. This code probably needs adjusted a little and would assume you create an Eloquent model for users currency in the same namespace
PHP:
public function currency ()
{
    return $this->hasMany(UserCurrency::class, 'user_id');
}

If you have a Discord, feel free to add me and ask me any Laravel questions as I use it daily at work. LeChris#9188
 
Last edited:

BrainCMS

Brain is live, Live is Brain
Feb 17, 2014
86
32
Your code is also redundant a bit and there is also no need to directly access the DB from the DB facade if you use Eloquent.

Example would be your client could just simply be
Auth::user()->update([ "sso" => $sso ]);

You also are not using relationships the right way; example on your user model would be. This code probably needs adjusted a little and would assume you create an Eloquent model for users currency in the same namespace
PHP:
public function currency ()
{
    return $this->hasMany(UserCurrency::class, 'user_id');
}

If you have a Discord, feel free to add me and ask me any Laravel questions as I use it daily at work. LeChris#9188
Tnx! I have add you on Discord
 

BrainCMS

Brain is live, Live is Brain
Feb 17, 2014
86
32
Add BrainCMS on GitHub

Post automatically merged:


Small edit plz tell me what you think about it, and what I can improve or change

MeController
PHP:
<?php
    
    namespace App\Http\Controllers;

    use Illuminate\Support\Facades\Auth;

    class MeController extends Controller {

        public function show() {
            return view('pages.me.show', [
                'currency' => Auth::user()->currency()->get()
            ]);
        }
    }

User Model
PHP:
<?php

    namespace App;

    use Illuminate\Notifications\Notifiable;
    use Illuminate\Foundation\Auth\User as Authenticatable;

    class User extends Authenticatable {

        use Notifiable;

        public $timestamps = false;

        protected $fillable = [
        'email', 'password', 'username', 'ip_register', 'ip_current', 'motto', 'last_login', 'account_created', 'auth_ticket',
        ];

        protected $hidden = [
        'password', 'remember_token',
        ];

        protected $table = 'users_currency';

        protected $primaryKey = 'user_id';

        public function currency (){
            return $this->hasMany(User::class, 'user_id')->select('amount','type');
        }
    }
Me Blade
PHP:
@extends('layouts.pages')

@section('title', 'Me')

@section('content')
    <div class="row">
        <div class="col-md-12">
            <div class="menu-user">
                Credits:{{ Auth::user()->credits }} <br>
                Duckets:
                @foreach ($currency->where("type", "5") as $object)
                    {{ $object->amount }}
                @endforeach
                <br>
                Diamonds:
                @foreach ($currency->where("type", "0") as $object)
                    {{ $object->amount }}
                @endforeach
            </div>
        </div>
</div>
@endsection
Post automatically merged:

Edits tnx to @LeChris

Clean up code + add currency model back
Update main HTTP structure
Remove useless files + add migrations + update README

Users_currency


PHP:
<?php
namespace App\Models\Player;
use Illuminate\Database\Eloquent\Model;
class Currency extends Model
{
    protected $table = 'users_currency';
    public $timestamps = false;
    protected $fillable = [];
}

Me Controller

PHP:
<?php
namespace App\Http\Controllers\Home;
use Auth;
use App\Http\Controllers\Controller;
class Me extends Controller
{
    public function render ()
    {
        return view('pages.user.home.me', [
            'currency' => Auth::user()->currency
        ]);
    }
}
 
Last edited:

Users who are viewing this thread

Top