Randy_Johnson

Randy_Johnson

Member Since 1 Year Ago

Experience Points
4,180
Total
Experience

820 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 your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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
4,180 XP
Mar
26
1 week ago
Activity icon

Started a new Conversation Fix My Ugly Code! Using Assets!

Hi I am using

{{ asset('storage/product') }}{{ '/'.$product->img }}

But I would much rather use something like

{{ asset('storage/product/$product->img') }}

or

{{ asset('storage/product'.$product->img) }}

But only the first one works, please help.

Mar
24
1 week ago
Activity icon

Started a new Conversation Great Hosting For Laravel

Any recommendations?

Mar
22
2 weeks ago
Activity icon

Started a new Conversation Javascript Not Working ( I Am New To It )

<select onclick="readonly()" class="form-control" id="exampleFormControlSelect1">
   function readOnly()
   {
      alert('Hello');
   }
Mar
21
2 weeks ago
Activity icon

Started a new Conversation Having A Checkbox As The Button To Post The Form

Hi, pretty much what the title says, is it possible?

Activity icon

Started a new Conversation Redirecting An Error To A 404!

Hi, when ever I leave the computer and the user is logged in, over a certain amount of time the user is logged out (of course, we all know, I'm sorry!). When this happens I refresh the page and I get the error:

Trying to get property 'is_admin' of non-object

The error isn't the problem, it is the showing of the error which I want to rid. I went into the code and tried putting an else statement as so:

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

@if(auth()->user()->is_admin == 1)
    @include('admin.home')
@elseif(auth()->user()->is_admin == 0)
    @include('user.home')
@else 
    @include('home')
@endif

@endsection

Please help!

Mar
19
2 weeks ago
Activity icon

Awarded Best Reply on Stripe Form Not Returning To Controller

I have managed to do what I needed, the form was missing an @csrf tag.

Mar
18
2 weeks ago
Activity icon

Started a new Conversation Database - Two Columns With The Same Name, One Overwriting On Join

Sorry for the long title but I didn't want to waste your time.

I have a problem where Ihave two tables and one table the entry is null where as on the other it contains information.

I want the information on the table that contains but it seems to be only wanting to read from the one that isn't containing the data. Here the code should explain it better than me.

$data = DB::table($this->table)
        ->join('products', 'products.id', '=', $this->table.'.item_id')
        ->where($this->table.'.user_id', '=', Auth::user()->id)
        ->get();
Activity icon

Replied to Installing Font-Awesome To Laravel Via Composer

Check to see if it is inside you public dir, if it isn't copy and paste it there.

Activity icon

Replied to Unable To Require Stripe/stripe Php

Yes, this was the problem, but the real problem is that stripe isn't detecting what payment method I am using when entering the test card number. I had to manually have it put in through the payment_method. This seems to have it working, but am still at lack of understanding to why this is happening.

When entering the card number you can see on the stripe element that it is saying visa, until I enter date and then icon changes.

Since putting this new code in, the icon will change to a blank card (unknown card) but when pressing the button, now it changes back to visa, which am guessing is reading from the $payment_intent->confirm([ 'payment_method' => 'pm_card_visa', ]);.

I feel that there is something wrong on the stripe end, maybe an error with a new update or something, or possible that is on my end, but I followed so many different tutorials, as well as the stripe tutorial, which all worked fine.

If you have any input I am all ears.

Mar
17
2 weeks ago
Activity icon

Replied to Unable To Require Stripe/stripe Php

Well, this wasn't the problem, but it helped me to find the real problem.

Anyone going through stripe payment and finding the payment isn't completing try sticking this in your controller after the payment intent.

$payment_intent->confirm([ 'payment_method' => 'pm_card_visa', ]);

Activity icon

Started a new Conversation Unable To Require Stripe/stripe Php

Help, I am pretty sure this is already install but I just tried to require it to see and I am getting this.

Laravel Framework 5.8.35
Using version ^7.27 for stripe/stripe-php
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install cartalyst/stripe-laravel v12.0.0
    - Conclusion: don't install cartalyst/stripe-laravel 12.x-dev
    - Conclusion: remove laravel/framework v5.8.35
    - Installation request for cartalyst/stripe-laravel ^12.0 -> satisfiable by cartalyst/stripe-laravel[12.x-dev, 12.0.x-dev, v12.0.0].
    - Conclusion: don't install laravel/framework v5.8.35
    - cartalyst/stripe-laravel 12.0.x-dev requires illuminate/support ^7.0 -> satisfiable by laravel/framework[7.x-dev], illuminate/support[7.x-dev, v7.0.0, v7.0.1, v7.0.2, v7.0.3, v7.0.4, v7.0.5, v7.0.6, v7.0.7, v7.0.8, v7.1.0, v7.1.1, v7.1.2, v7.1.3, v7.2.0].
    - Can only install one of: laravel/framework[7.x-dev, v5.8.35].
    - don't install illuminate/support 7.x-dev|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.0.0|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.0.1|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.0.2|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.0.3|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.0.4|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.0.5|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.0.6|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.0.7|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.0.8|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.1.0|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.1.1|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.1.2|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.1.3|don't install laravel/framework v5.8.35
    - don't install illuminate/support v7.2.0|don't install laravel/framework v5.8.35
    - Installation request for laravel/framework (locked at v5.8.35, required as 5.8.*) -> satisfiable by laravel/framework[v5.8.35].


Installation failed, reverting ./composer.json to its original content.

Mar
14
3 weeks ago
Activity icon

Started a new Conversation Purchase Model Not Found

Class 'App\Http\Controllers\Customer\App\Purchase' not found
use App\Purchase;

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

use Auth;
use Carbon\Carbon;

class PurchaseController extends BaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $purchases = App\Purchase::all();
        dd($purchases);
    }
Mar
01
1 month ago
Activity icon

Replied to Stripe Form Not Returning To Controller

I have managed to do what I needed, the form was missing an @csrf tag.

Activity icon

Started a new Conversation Stripe Form Not Returning To Controller

Hi, I am attempting to set up a stripe payment system, I have it where I am receiving a 200 OK from the token, my only problem now is that the page is not returning to the controller.

Please help.

<form id="payment-form" action="/user/payment/stripe" method="POST">
            <div id="card-element">
               <!-- Elements will create input elements here -->
            </div>
            <!-- We'll put the error messages in this element -->
            <div id="card-errors" role="alert"></div>
            <button id="submit" type="submit" class="btn btn-primary btn-lg btn-block mt-3">Pay</button>
         </form>
<script>
   // Create a Stripe client.
   var stripe = Stripe('xxxx xxxx xxxx xxxx xxxx);
   
   // Create an instance of Elements.
   var elements = stripe.elements();
   
   // Custom styling can be passed to options when creating an Element.
   // (Note that this demo uses a wider set of styles than the guide below.)
   var style = {
   base: {
      color: '#32325d',
      fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
      fontSmoothing: 'antialiased',
      fontSize: '16px',
      '::placeholder': {
         color: '#aab7c4'
      }
   },
   invalid: {
      color: '#fa755a',
      iconColor: '#fa755a'
   }
   };
   
   // Create an instance of the card Element.
   var card = elements.create('card', {style: style});
   
   // Add an instance of the card Element into the `card-element` <div>.
   card.mount('#card-element');
   
   // Handle real-time validation errors from the card Element.
   card.addEventListener('change', function(event) {
   var displayError = document.getElementById('card-errors');
   if (event.error) {
      displayError.textContent = event.error.message;
   } else {
      displayError.textContent = '';
   }
   });
   
   // Handle form submission.
   var form = document.getElementById('payment-form');
   form.addEventListener('submit', function(event) {
   event.preventDefault();
   
   stripe.createToken(card).then(function(result) {
      if (result.error) {
         // Inform the user if there was an error.
         var errorElement = document.getElementById('card-errors');
         errorElement.textContent = result.error.message;
      } else {
         // Send the token to your server.
         stripeTokenHandler(result.token);
      }
   });
   });
   
   // Submit the form with the token ID.
   function stripeTokenHandler(token) {
      // Insert the token ID into the form so it gets submitted to the server
      var form = document.getElementById('payment-form');
      var hiddenInput = document.createElement('input');
      hiddenInput.setAttribute('type', 'hidden');
      hiddenInput.setAttribute('name', 'stripeToken');
      hiddenInput.setAttribute('value', token.id);
      form.appendChild(hiddenInput);
   
      // Submit the form
      form.submit();
   }
</script>
Feb
16
1 month 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
1 month 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
1 month 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 month 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 month 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 month 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 month 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 month 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 month 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
2 months 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
2 months 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
2 months 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
3 months 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
3 months 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
3 months 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
3 months 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
3 months 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"),
        ]);
}