Randy_Johnson

Randy_Johnson

Member Since 1 Year Ago

Experience Points
3,640
Total
Experience

1,360 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
7
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
3,640 XP
Feb
16
3 days ago
Activity icon

Replied to Admin And User Login Pages

Yes this is what i did. And i am very happy that i did.

Feb
15
4 days ago
Activity icon

Started a new Conversation DB Where And - Is It Possible?

I am trying to do something like this, but looking in the documentation I could not find anything.

DB::table($this->tablex)->where('user_id', '=', Auth::user()->id)->and('product_id', '=', $slug)->delete();
Feb
14
5 days ago
Activity icon

Replied to Admin And User Login Pages

404 bro on the url. I currently have a system like this and this is my file structure.

Controllers Admin - products - etc User - products - etc

The thing is, is products is the same thing but both products is different in that is serving two group's. To have one would have it too big. I think i just answered this one for myself but i would appreciate your inputs.

Going on to views i have the same lay out

Admin - products User - products

Both are technically the same but display different. Would it be best to have admin user displayed in one. I think not.

I think that splitting everything to the users need is the best way.

Ah like i say any input is welcome. I think this post is just really on how to organize.

Activity icon

Started a new Conversation Admin And User Login Pages

Hi, I was just wondering if it is better to have a login page for admin and a separate login page for standard users - or just to ultimately go through the same login system. With this said it would also be asked, is it better to have one database for admin and another for standard user?

Another question is should I have two separate common pages or should I just have one page with some if statements displaying different buttons.

Also, should I have a User and Admin controller for the same things, or should I just stick them in one common controllers.

Feb
12
1 week ago
Activity icon

Replied to Database Help -> Join With Where!

Sorry.

return DB::table('users')->join('carts', function ($join) {
            $join->on('users.id', '=', 'carts.user_id')
                ->where('carts.user_id', '=', Auth::user()->id);
            })->get();
        }

Activity icon

Started a new Conversation Database Help -> Join With Where!

The code below isn't working but am guessing from looking at it you can catch my drift of what I am going for. I haven't implemented and Eloquent stuff yet because I never did models, since am looking for perfection on the project its something I will just go over and tie in at the end so for the mean time, if possible can we skip on the Eloquent.

return $users = DB::table($this->tablex)
            ->join('users', 'users.id', '=', 'carts.user_id')
            ->where(Auth::user()->id, '=', 'carts.user_id')
            ->get();
Feb
11
1 week ago
Activity icon

Replied to Error On DB Where!

There are only around 30 records. I think the problem is a simple one I haven't had time to sit at my computer. :*(

Feb
10
1 week ago
Activity icon

Started a new Conversation Two Controllers Or One?

Is it better to have one controller that will handle user stuff and one to handle admin, or should I just bang it all inside one.

Activity icon

Replied to Install Phpmyadmin On Linux

Install xampp is come in the package. Uninstall any previous apps that will conflict.

Feb
09
1 week ago
Activity icon

Replied to Error On DB Where!

Just on my way to work will give it a try when I get home.

Activity icon

Replied to Error On DB Where!

public function __construct() { parent::__construct(); $this->tablex = "carts"; $this->rv = "user/cart/read"; }

Activity icon

Started a new Conversation Error On DB Where!

    public function index()
    {
        $data = DB::table($this->tablex)->where('user_id', Auth::user()->id);
        print_r($data);
    }
"Allowed memory size of 134217728 bytes exhausted (tried to allocate 60821504 bytes)"
Activity icon

Replied to Best Practices For Occasional Coding On A Large Project?

Organization is key. But on my project I think I went too far. I created separate controllers for the user and admin. I still don't know yet if it is a good thing or a bad thing, I suppose it has its pros and cons.

Feb
08
1 week ago
Activity icon

Replied to Jquery Help

@extends('layouts.app')
 
@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <div class="font-weight-bold" style="font-size: 1em;">
                        Product Description
                        <a href="{{ url('products') }}" class="btn btn-dark float-right ml-2">Back</a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col">
                            <img class="img-thumbnail mx-left d-block shadow mx-auto" style="width: 300px; height: 300px;" src="{{ URL::asset('storage/img/product/'.$products->img) }}">
                        </div>
                        <div class="col">
                            <form method="POST" action="/add-to-cart" enctype="multipart/form-data">
                            @csrf
                                <div class="form-group">
                                    <label>Name</label>
                                    <input name="name" type="" class="form-control" placeholder="Enter name" value="{{ $products->name }}" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="exampleFormControlTextarea1">Description</label>
                                    <textarea name="description" class="form-control" id="exampleFormControlTextarea1" rows="3" readonly>{{ $products->description }}</textarea>
                                </div>
                                <div class="form-group">
                                    <label>Price Per KG (GBP)</label>
                                    <input id="price" name="price" class="form-control" placeholder="Enter price" value="{{ $products->price }}" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="exampleFormControlSelect1">Amount</label>
                                    <select id="amount" name="amount" class="form-control">
                                    <option>1</option>
                                    <option>2</option>
                                    <option>3</option>
                                    <option>4</option>
                                    <option>5</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>Price (GBP)</label>
                                    <input id="total" name="name" type="number" class="form-control" value="0.00" readonly>
                                </div>
                                <!-- <button type="submit" class="btn btn-outline-success w-25" formaction="{{ url('calculate-product/'.$products->id) }}">Calculate</button> -->
                                <div id="calculate" type="button" class="btn btn-warning w-25">Calculate</div>
                                <button type="submit" class="btn btn-success w-25">Add</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    var amount = $("#amount");
    var price = $("#price");
    $("#calculate").click(function () {
        var total = parseInt(amount.val()||0) + parseInt(price.val()||0);
        alert(total);
        $("#totalamountremaining").val(total);
    })
</script>

@endsection

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="iJFfY4kxAYWg02Viq07K1n1w10kWqIHA42v8VSUI">

    <title>T-Tobacco</title>

    <!-- Scripts -->
    <script src="http://127.0.0.1:8000/js/app.js" defer></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <!-- Styles -->
    <link href="http://127.0.0.1:8000/css/app.css" rel="stylesheet">

    
</head>
<body>
    <div id="app">
        <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
            <div class="container">
                <a class="navbar-brand" href="http://127.0.0.1:8000">
                    T-Tobacco
                </a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!-- Left Side Of Navbar -->
                    <ul class="navbar-nav mr-auto">
                        
                    </ul>

                    <!-- Right Side Of Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <!-- Authentication Links -->
                                                    <li class="nav-item dropdown">
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                    6OoxPVh2u2 <span class="caret"></span>
                                </a>
                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                
                                    
                                    <a class="dropdown-item" href="http://127.0.0.1:8000/logout"
                                       onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                        Logout
                                    </a>

                                    <form id="logout-form" action="http://127.0.0.1:8000/logout" method="POST" style="display: none;">
                                        <input type="hidden" name="_token" value="iJFfY4kxAYWg02Viq07K1n1w10kWqIHA42v8VSUI">                                    </form>
                                </div>
                            </li>
                                            </ul>
                </div>
            </div>
        </nav>
        <main class="py-4">
            <div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <div class="font-weight-bold" style="font-size: 1em;">
                        Product Description
                        <a href="http://127.0.0.1:8000/products" class="btn btn-dark float-right ml-2">Back</a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col">
                            <img class="img-thumbnail mx-left d-block shadow mx-auto" style="width: 300px; height: 300px;" src="http://127.0.0.1:8000/storage/img/product/tabacco1_1580844418.jpg">
                        </div>
                        <div class="col">
                            <form method="POST" action="/add-to-cart" enctype="multipart/form-data">
                            <input type="hidden" name="_token" value="iJFfY4kxAYWg02Viq07K1n1w10kWqIHA42v8VSUI">                                <div class="form-group">
                                    <label>Name</label>
                                    <input name="name" type="" class="form-control" placeholder="Enter name" value="aXLj3zxypD" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="exampleFormControlTextarea1">Description</label>
                                    <textarea name="description" class="form-control" id="exampleFormControlTextarea1" rows="3" readonly>ztkriXj9TfhlQFOHd4B6Wwe0aPkwnPrz0pKZrYwIzeWPsJLFJ53x1OCPO2uuSbaKUeXQKMP2mnZ7lNdyKijQ810dvnbSaTlNtGKW</textarea>
                                </div>
                                <div class="form-group">
                                    <label>Price Per KG (GBP)</label>
                                    <input id="price" name="price" class="form-control" placeholder="Enter price" value="5" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="exampleFormControlSelect1">Amount</label>
                                    <select id="amount" name="amount" class="form-control">
                                    <option>1</option>
                                    <option>2</option>
                                    <option>3</option>
                                    <option>4</option>
                                    <option>5</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>Price (GBP)</label>
                                    <input id="total" name="name" type="number" class="form-control" value="0.00" readonly>
                                </div>
                                <!-- <button type="submit" class="btn btn-outline-success w-25" formaction="http://127.0.0.1:8000/calculate-product/1">Calculate</button> -->
                                <div id="calculate" type="button" class="btn btn-warning w-25">Calculate</div>
                                <button type="submit" class="btn btn-success w-25">Add</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    var amount = $("#amount");
    var price = $("#price");
    $("#calculate").click(function () {
        var total = parseInt(amount.val()||0) + parseInt(price.val()||0);
        alert(total);
        $("#totalamountremaining").val(total);
    })
</script>

        </main>
    </div>
</body>
</html>


Activity icon

Replied to Jquery Help

Oh, sorry, it doesn't work. But from your response am guessing there is nothing wrong with the code.

Activity icon

Started a new Conversation Jquery Help

I am trying to cal the amount and price, I was originally going to do it through PHP but realized it would be much more efficient doing it through jquery.

I am follow this:

https://jsfiddle.net/jakecigar/pTQgB/1/

Here is my code:

<div class="card-body">
                    <div class="row">
                        <div class="col">
                            <img class="img-thumbnail mx-left d-block shadow mx-auto" style="width: 300px; height: 300px;" src="{{ URL::asset('storage/img/product/'.$products->img) }}">
                        </div>
                        <div class="col">
                            <form method="POST" action="/add-to-cart" enctype="multipart/form-data">
                            @csrf
                                <div class="form-group">
                                    <label>Name</label>
                                    <input name="name" type="" class="form-control" placeholder="Enter name" value="{{ $products->name }}" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="exampleFormControlTextarea1">Description</label>
                                    <textarea name="description" class="form-control" id="exampleFormControlTextarea1" rows="3" readonly>{{ $products->description }}</textarea>
                                </div>
                                <div class="form-group">
                                    <label>Price Per KG (GBP)</label>
                                    <input id="price" name="price" class="form-control" placeholder="Enter price" value="{{ $products->price }}" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="exampleFormControlSelect1">Amount</label>
                                    <select id="amount" name="amount" class="form-control" id="exampleFormControlSelect1">
                                    <option>1</option>
                                    <option>2</option>
                                    <option>3</option>
                                    <option>4</option>
                                    <option>5</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>Price (GBP)</label>
                                    <input id="total" name="name" type="number" class="form-control" value="0.00" readonly>
                                </div>
                                <!-- <button type="submit" class="btn btn-outline-success w-25" formaction="{{ url('calculate-product/'.$products->id) }}">Calculate</button> -->
                                <div id="calculate" type="button" class="btn btn-warning w-25">Calculate</div>
                                <button type="submit" class="btn btn-success w-25">Add</button>
                            </form>
                        </div>
                    </div>
                </div>
<script>
    var amount = $("#amount");
    var price = $("#price");
    $("#calculate").click(function () {
        var total = parseInt(amount.val()||0) + parseInt(price.val()||0);
        alert(total);
        $("#totalamountremaining").val(total);
    })
</script>
Activity icon

Replied to Array Issue

Yes that would be the case. It is assigned to the return of a single DB entry. I am thinking now I have to create a separate array and push it onto the $data, would this be the case?

Feb
07
1 week ago
Activity icon

Started a new Conversation Array Issue

$data['price'] = $request->input('amount') * $request->input('price');
Cannot use object of type stdClass as array
Jan
19
1 month ago
Activity icon

Started a new Conversation Uploading An Image In Laravel

  public function store(Request $request)
    {
        if(DB::table($this->table)->insert(
            [   
                'name' => $request->input('name'), 
                'description' => $request->input('description'),
                'price' => $request->input('price'),
                'kg' => $request->input('kilogram'),
                'type' => $request->input('type'),
                'img' => $request->input('image'),
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now() 
            ]
        ))
        {
            $path = Storage::putFile('public/img/product', $request->file('image'));
            return redirect()->route($this->table);
        }
        else 
        {
            return abort(404);
        }
    }
    /**
     * Store the uploaded file on the disk.
     *
     * @param  string  $path
     * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
     * @param  array  $options
     * @return string|false
     */
    public function putFile($path, $file, $options = [])
    {
        return $this->putFileAs($path, $file, $file->hashName(), $options);
    }
 
    /**
     * Store the uploaded file on the disk with a given name.
     *
     * @param  string  $path
     * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
     * @param  string  $name
     * @param  array  $options
     * @return string|false
     */
    public function putFileAs($path, $file, $name, $options = [])
    {
        $stream = fopen($file->getRealPath(), 'r');

Call to a member function hashName() on null

Activity icon

Started a new Conversation Displaying A 3 By N Grid With Db Data In Blade.

Okay, so you can see my attempt... I will probably figure it out after tinkering but there must be an easier way, since its such a common feature!

@extends('layouts.app')

@section('title', 'Products')

@section('content')

<div class="container">

    @for($x = 0; $x <= count($products) / 3; $x++)
    
        <div class="row">

        @for($y = 0; $y == 3; $y++)

            <div class="col-lg-4">
                <div class="card" style="width: 18rem;">
                    <img src="{{ asset('img/product/1.jpg') }}" class="card-img-top" alt="...">
                    <div class="card-body">
                        <h5 class="card-title">{{ $product->name }}</h5>
                        <p class="card-text">{{ $product->description }}</p>
                        <a href="#" class="btn btn-primary">Buy</a>
                    </div>
                </div>
            </div>

        @endfor
            
        </div>

    @endfor
    

</div>

@endsection
Activity icon

Started a new Conversation Sending And Opening Multiple Varibles In The View.

Hello, I am trying to make a create order page. I am just wondering what is the proper way of doing it.

Undefined variable: data (View: C:\Users\Josh\Desktop\websites\ecommerce\resources\views\admin\order\create.blade.php)
    public function create() 
    {
        $data = [
            'users' => DB::table('users')->get(),
            'products' => DB::table('products')->get()
        ];
        return view($this->cv, [$this->table => $data]);
    }
<form method="POST" action="/store-order">
                                @csrf
                                <div class="form-group">
                                    <label for="exampleFormControlSelect1">User</label>
                                    <select name="kilogram" class="form-control">
                                    @foreach($data['users'] as $user)
                                    <option>0.25</option>
                                    @endforeach
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="exampleFormControlSelect1">Product</label>
                                    <select name="kilogram" class="form-control">
                                    <option>0.25</option>
                                    <option>0.5</option>
                                    <option>1</option>
                                    <option>2</option>
                                    <option>3</option>
                                    <option>4</option>
                                    <option>5</option>
                                    </select>
                                </div>
                                <button type="submit" class="btn btn-primary float-right">Create</button>
                            </form>
Jan
17
1 month ago
Activity icon

Replied to Variable Cannot Be Found In Parent Controller Php

Oh my God I was staring at this for an hour before bed. How did I not see! Merci

Jan
16
1 month ago
Activity icon

Started a new Conversation Variable Cannot Be Found In Parent Controller Php

<?php

namespace App\Http\Controllers\Customer;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    protected $table;       // Database table name
    protected $p;           // Page
    protected $sf;          // Search functionality 

    public function __construct() {
        
    }

    public function index()
    {
        return view($this->p);
    }

    public function search()
    {
        return view($this->sf);
    }
}
<?php

namespace App\Http\Controllers\Customer;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ProductController extends BaseController
{
    public function __construct() { 
        parent::__construct();
        $this->$table = "products";       
        $this->$p = "user/products";  
        echo "I am here!";          
    }
}
Jan
05
1 month ago
Activity icon

Replied to Controller Organisation!

Now I have the error of

Class 'App\Http\Controllers\Admin\Controller' not found

with the Controller being in the previous directory!

Activity icon

Replied to Controller Organisation!

I did this but now I have a problem with an error saying:

Class App\Http\Controllers\Admin\UserController does not exist

My files look as such:

app > http > Controllers > Admin >

UserController

etc....

User Controller

<?php

namespace App\Http\Controllers\Admin;
namespace App\Http\Controllers;

use App\User;
use Carbon\Carbon;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class UserController extends AdminBaseController
{
    public function __construct() { 
        parent::__construct();
        $this->table = "users"; 
        $this->cv = "admin/user/create";
        $this->rv = "admin/user/read"; 
        $this->rsv = "admin/user/read-user";
        $this->ev = "admin/user/edit";
    }

    public function store(Request $request)
    {
        if(DB::table($this->table)->insert(
            [   
                'name' => $request->input('name'), 
                'email' => $request->input('email'),
                'password' => bcrypt($request->input('password')),
                'is_admin' => $request->input('is_admin'),
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now() 
            ]
        ))
        {
            return redirect()->route('read-users');
        }
        else 
        {
            return abort(404);
        }
    }

    public function update(Request $request)
    {
        if(DB::table($this->table)
            ->where('id', $request->input('id'))
            ->update(array
                (
                    'name' => $request->input('name'),
                    'email' => $request->input('email'),
                    'password' => bcrypt($request->input('password')),
                    'is_admin' => $request->input('is_admin'),
                    'updated_at' => Carbon::now()
                )
            ))
            {
                return redirect()->route('read-users');
            }
            else 
            {
                return abort(404);
            }
    }
}

Activity icon

Started a new Conversation Controller Organisation!

I stuck all my admin controllers inside a folder called admin. How do I now access them via the routes.

Route::get('/create-user', '[email protected]')->middleware('admin');
Route::post('/store-user', '[email protected]')->middleware('admin');
Route::get('/read-users', '[email protected]')->middleware('admin')->name('read-users');
Route::get('/read-user/{slug}', '[email protected]')->middleware('admin');
Route::get('/edit-user/{slug}', '[email protected]')->middleware('admin');
Route::post('/update-user', '[email protected]')->middleware('admin');
Route::get('/delete-user/{slug}', '[email protected]')->middleware('admin');
Route::post('/search-user', '[email protected]')->middleware('admin');
Jan
04
1 month ago
Activity icon

Started a new Conversation Using Models

I have been creating a website I am have come to the realisation that I haven't been using models, and now I am thinking, should I be using models.

Here is an example of two of my controllers, one being basecontroller and usercontroller, I have used this base class so that I can inherit for all my other controllers and just pass in data that is specific to each class. I don't know if this is the correct way to go about it but it was the quicker. I could not help but notice that all get methods would nicely fit into this section, where, post and put methods would go into its individual controller.

Now to the point, I haven't used models, and its concerning me, should I be using, and if you can whilst you are here, can you point out everything wrong with my work... Sorry for the big ask.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class BaseController extends Controller
{
    protected $table;       // Database table name
    protected $cv;          // Create view
    protected $rv;          // Read view
    protected $rsv;         // Read single view
    protected $ev;          // Edit view
    protected $sf;          // Search functionality

    public function __construct() {
        $this->middleware('auth');
    }

    public function create() 
    {
        return view($this->cv);
    }

    public function read() 
    {
        if ($data = DB::table($this->table)->simplePaginate(15))
        {
            return view($this->rv, [$this->table => $data]);
        }
        else 
        {
            return abort(404);
        }
    }

    public function readSingle($slug) 
    {
      if ($data = DB::table($this->table)->where('id', $slug)->first())
      {
          return view($this->rsv, [$this->table => $data]);
      }
      else 
      {
          return abort(404);
      }
    }

    public function edit($slug) 
    {
        if ($data = DB::table($this->table)->where('id', $slug)->first())
        {
            return view($this->ev, [$this->table => $data]);
        }
        else 
        {
            return abort(404);
        }
    }

    public function delete($slug)
    {
        if (DB::table($this->table)->where('id', '=', $slug)->delete())
        {
            return redirect()->route('read-users');
        } 
        else 
        {
            return abort(404);
        }
    }

    public function search(Request $request)
    {
        if ($data = DB::table($this->table)->where('name', $request->input('search'))->first())
        {
            return view($this->rsv, [$this->table => $data]);
        }
        else 
        {
            return abort(404);
        }
    }
}
<?php

namespace App\Http\Controllers;

use App\User;
use Carbon\Carbon;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class UserController extends BaseController
{
    public function __construct() { 
        parent::__construct();
        $this->table = "users"; 
        $this->cv = "admin/user/create";
        $this->rv = "admin/user/read"; 
        $this->rsv = "admin/user/read-user";
        $this->ev = "admin/user/edit";
    }

    public function store(Request $request)
    {
        if(DB::table($this->table)->insert(
            [   
                'name' => $request->input('name'), 
                'email' => $request->input('email'),
                'password' => bcrypt($request->input('password')),
                'is_admin' => $request->input('is_admin'),
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now() 
            ]
        ))
        {
            return redirect()->route('read-users');
        }
        else 
        {
            return abort(404);
        }
    }

    public function update(Request $request)
    {
        if(DB::table($this->table)
            ->where('id', $request->input('id'))
            ->update(array
                (
                    'name' => $request->input('name'),
                    'email' => $request->input('email'),
                    'password' => bcrypt($request->input('password')),
                    'is_admin' => $request->input('is_admin'),
                    'updated_at' => Carbon::now()
                )
            ))
            {
                return redirect()->route('read-users');
            }
            else 
            {
                return abort(404);
            }
    }
}
Jan
01
1 month ago
Activity icon

Started a new Conversation Blade Laravel - Two Yields In The Same View.

I am trying to do something as shown below.

@extends('layouts.app')
 
@section('content')

@if(auth()->user()->is_admin == 1)
    @yield('content', View::make('view.admin'))
@else
    @yield('content', View::make('view.user'))
@endif

@endsection
Dec
25
1 month ago
Activity icon

Started a new Conversation Updating User DB

Hi, I am having trouble updating user, there is no error, it just doesn't run.

Edit: I have a problem where the id is missing, I could easily put a input which isn't editable and push to the controller, but I would rather do it another way. I tried adding {slug} in the routes, but my method already has Request request in the parameters.

How do I get the id?

        if(DB::table('users')
            ->where('id', $request->input('id'))
            ->update(
                [
                    'name' => $request->input('name'),
                    'email' => $request->input('email'),
                    'password' => bcrypt($request->input('password')),
                    'is_admin' => $request->input('is_admin'),
                    'updated_at' => Carbon::now(),
                ]
            ))
            {
                return redirect()->route('read-users');
            }
            else 
            {
                return abort(404);
            }
Activity icon

Started a new Conversation Route Is Not Defined

I am trying to redirect to read users but I am having issues finding it, I think maybe it is something to do with the middleware.

Route::get('/read-users', '[email protected]')->middleware('admin');
return redirect()->route('read-user');
Route [admin] not defined.
Activity icon

Replied to No Understanding Of REQUEST!

Ah Okay! It doesn't want to work like that, I have all the auto auth implemented and now I am making it so that the admin can create users by him self to add into the database.

Maybe someone is having trouble or something, I cannot think of a reason why but I think its good to have.

Activity icon

Replied to No Understanding Of REQUEST!

... Yeah thats a really good point!

Dec
24
1 month ago
Activity icon

Replied to No Understanding Of REQUEST!

Terrible sorry I had to fix the mark up so it looks correct. Well, it should be return name, email, pass etc... but all I seem to get is this bloody token.

Activity icon

Started a new Conversation No Understanding Of REQUEST!

On my view:

<form method="POST" action="/store-user">
                                @csrf
                                <div class="form-group">
                                    <label>Name</label>
                                    <input name="name" type="" class="form-control" placeholder="Enter name">
                                </div>
                                <div class="form-group">
                                    <label>Email Address</label>
                                    <input name="email" type="email" class="form-control" placeholder="Enter email">
                                </div>
                                <div class="form-group">
                                    <label>Password</label>
                                    <input name="password" class="form-control" placeholder="Enter password">
                                </div>
                                <div class="form-group">
                                    <label for="exampleFormControlSelect1">Admin</label>
                                    <select name="is_admin" class="form-control">
                                    <option>0</option>
                                    <option>1</option>
                                    </select>
                                    <small class="form-text text-muted">Select 0 for user and 1 for admin level status.</small>
                                </div>
                                <button type="submit" class="btn btn-primary float-right">Create</button>
                            </form>

Route:

Route::post('/store-user', '[email protected]')->middleware('admin');

Controller:

public function store(Request $request)
    {
        return $request->all();
    }

Result:

{"_token":"0EBiLnf8jUQ3i8xsYRCmtdQXt9XalVzSLmUS8wxN"}
Activity icon

Started a new Conversation Displaying The User Creation Page And Storing Details

Is it better to have two seperate function, one for displaying of the user creation page, and one for the storing, or is it okay to just stick it in one function.

Activity icon

Replied to Running A Loop Whilst Seeding Db

No, I mean like this:

for($i = 0; $i > 100; $i ++)
{
DB::table('users')->insert([
            'name' => str_random(10),
            'email' => str_random(10).'@gmail.com',
            'password' => bcrypt('user'),
            'is_admin' => 0,
            'created_at' => date("Y-m-d H:i:s"),
            'updated_at' => date("Y-m-d H:i:s"),
        ]);
}
Activity icon

Started a new Conversation Running A Loop Whilst Seeding Db

Hey I just tried running a loop whilst seeding my db. But the seed wasn't successful, even though everything ran fine the entries were never put inside the database.

Is it possible for me to do what I was?

Edit!?

Also I am unable to move the pagination to the bottom of the page. It just sits at the top no matter what I do.

Activity icon

Started a new Conversation Blade URL With Varaible

Hi, the first url isn't working correctly. But the second one does, I am just asking what is the correct way to do this because the first looks clean and the second, not so...

{{ url('delete-user/{{$user->id}}') }}

{{ url('delete-user/') }}/{{ $user->id }}

Dec
22
1 month ago
Activity icon

Replied to Controller Inheritence In Laravel?

Everything is working great, thank you ever so much.

{
    public function __construct() { 
        parent::__construct();
        $this->table = "products"; 
        $this->view ="admin/product/read"; 
    }
}
Activity icon

Replied to Controller Inheritence In Laravel?

I just have one more question.

My products controller looks like this:

class ProductController extends UserController { public function __construct() { $this->middleware('auth'); $this->table = "products"; $this->view ="admin/product/read"; } }

and I am getting the error of

SQLSTATE[HY000]: General error: 1096 No tables used (SQL: select *)

Clearly I am doing something wrong here but what I do not know.

Activity icon

Started a new Conversation Controller Inheritence In Laravel?

Sorry guys, running in one problem to another, but am just wondering how do I pass variable. I assumed it would be something as simple as this.

class UserController extends Controller { private $table; private $view;

public function __construct() {
    $this->middleware('auth');
    $this->$table = "users";
    $this->view ="admin/user/read";
}

public function create() {

}

public function read() {
    $data = DB::table($this->table)->get();
    return view($this->view, [$this->table => $data]);
}

public function readSingle() {}

public function update() {}

public function delete($slug)
{

}

}

Activity icon

Started a new Conversation Undefined Variable - But It Is There I Promise.

Undefined variable table.

namespace App\Http\Controllers;

use Illuminate\Http\Request; use Illuminate\Support\Facades\DB;

class UserController extends Controller { private $table = 'users'; private $view = 'admin/user/read';

public function __construct() {
    $this->middleware('auth');
}

public function create() {

}

public function read() {
    $data = DB::table($table)->get();
    return view($view, [$table => $data]);
}

public function readSingle() {}

public function update() {}

public function delete($slug)
{
}

}

Activity icon

Replied to Layouts.app Not Working

I apologise, I forgot to add .blade. to the file name.

Activity icon

Started a new Conversation Layouts.app Not Working

I am unable to read layouts.app and I feel its because I stuff blade.php file a couple of layers deep into the folder system, I tried using ../../layouts.app with no luck.

Routes

Route::get('/users', '[email protected]')->middleware('admin');

User Controller

public function read() {
    $users = DB::table('users')->get();
    return view('admin/user/read', ['users' => $users]);
}

View

view > admin > user > read

@extends('layouts.app')

@section('content')

bunch of html here

@endsection

Dec
21
1 month ago
Activity icon

Started a new Conversation Seeder Variable Types

I am wanting to plant my seeds into the database but my db isn't playing ball, Ive tried everything, bought flowers, chocolates etc, but it just isn't working...

Jokes aside!

I am just wondering how I insert other randoms variable types, I know string is str_random(), but I want to do random for a double, how is this done?

Dec
11
2 months ago
Activity icon

Started a new Conversation Access Level On Laravel 5.6 Make:auth

Hi, I am wanting to add access level column to the user database table and I was wanting some guidance before I attempt it. I just followed a tutorial which was pretty complex and I didn't so much understand (could be since I was reading from my phone* not internet) and was wondering if anyone has a good tutorial for admin access.

I was wanting somewhere where I can just add access level column 0 admin, 1 user etc...

Dec
06
2 months ago
Activity icon

Started a new Conversation 000webhost SSL Working Then Not Working

Hi I have a website with an ssl which decides to work and then not work and work etc..

My website is teachingdocs.000webhostapp.com

İt seems during the day it stops working but at night it works, it is so strange.

İt's giving me this address now http://88.255.216.16/landpage?op=1&ms=http://teachingdocs.000webhostapp.com/

My ssl was a free one. İt's not good that o cannot remember buy it's in the top 10 on a Google search. I am at work atm so I cannot stay on my phone to long so I hope you understand and can help.

Dec
03
2 months ago
Activity icon

Replied to 000webhost Can Log In, But Unable To Register

Hey thanks, I just had to make my remember token nullable.

Activity icon

Started a new Conversation 000webhost Can Log In, But Unable To Register

Hi, I have come to the final stage of that having an account already in the db, I can log in, but when it comes to creating an account I keep getting the page, whoops something went wrong.

I get a status code of 500: internal server error, and the fact that I can login with an account made through phpmyadmin must mean the problem lies within the sending of the information to the server.

I am clueless so please help!

Activity icon

Replied to 000webhost Login Register 404

I thought this may be the problem, I downloaded a .htaccess file but then only a white page was presented at /. So I changed it back. Can anyone tell me where to find the htaccess. I couldn't find the original on the upload. So am guessing I can just try uploading it again from my own environment. At work ATM so I don't have access to a computer. Lemme know for any insight