greevesh

greevesh

Web Developer (Laravel) at Freelancer

Member Since 3 Months Ago

Experience Points
7,510
Total
Experience

2,490 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
60
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 2
7,510 XP
Jan
12
1 week ago
Activity icon

Replied to ENV Variables Remain The Same After Clearing Cache

@snapey

No. I haven't changed that file.

Activity icon

Replied to ENV Variables Remain The Same After Clearing Cache

@snapey @claudsonm

So, I finally managed to get my new env credentials to display in my email template. Strangely, it was by running php artisan config:cache.

But when I clear my cache with php artisan config:clear my old credentials reappear. Isn't this the exact opposite to what's supposed to happen?!

Jan
11
1 week ago
Activity icon

Replied to ENV Variables Remain The Same After Clearing Cache

@claudsonm

I've ran Cache::clear() in tinker and it returns true. So it's definitely been cleared? I've never used Redis and I'm not sure how I would clear it anyway. Unless that's what Laravel uses by default?

Thanks for your help

Activity icon

Replied to ENV Variables Remain The Same After Clearing Cache

@snapey

Thanks for the tip. I'll definitely be using that. However, when I run that command in tinker it shows my new app name. Yet, when using ```{{ config('app.name') }} in my email template, it sends me the email with the old app name. This doesn't make sense to me. How about you?

Activity icon

Started a new Conversation ENV Variables Remain The Same After Clearing Cache

I've been doing some email testing with mailtrap. I've now decided to change my .env credentials to those from my mailgun account. I've also changed my app name.

Yet after doing so and clearing my cache using php artisan config:clear and php artisan cache:clear. My email is still being sent on mailtrap with my old app name. Even though I changed the credentials from mailtrap to mailgun.

I thought this would be all I have to do for my changes to take place. What else do I have to do?

Thanks

Jan
05
2 weeks ago
Activity icon

Replied to Laravel 6.0 And PHP 7.4: SQLSTATE[HY000] [2002] No Such File Or Directory

All I needed to do was start MySQL. That would explain why the restart commands weren't working. I never disconnected from MySQL manually but I read on SO that if you have multiple instances of MySQL, problems like these can take place. This makes sense as I recently installed XAMMP.

Maybe it wasn't the PHP upgrade after all.

Thank you both.

Activity icon

Replied to Laravel 6.0 And PHP 7.4: SQLSTATE[HY000] [2002] No Such File Or Directory

Root is the only username I have. I tried connecting through the terminal and I got the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
Activity icon

Started a new Conversation Laravel 6.0 And PHP 7.4: SQLSTATE[HY000] [2002] No Such File Or Directory

I just upgraded my PHP version from 7.2 to 7.4 and now whenever I try to run a query, I get this error. Here are my relevant .env credentials:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306

I've tried as many have suggested and tried changing the DB_HOST to 127.0.0.1 and I get this error instead:

SQLSTATE[HY000] [2002] Connection refused

This is the first time I've ever performed a PHP upgrade. Is it normal to have issues like this? Particularly with Laravel?

Thanks

Dec
24
3 weeks ago
Activity icon

Replied to Bootstrap Not Integrating With Laravel 6.0

Forgot to include the link tag! Thanks.

Dec
23
3 weeks ago
Activity icon

Started a new Conversation Bootstrap Not Integrating With Laravel 6.0

I'm trying to integrate a Bootstrap template into my welcome.blade.php but no CSS is rendering. I've installed and ran NPM dev and I have Bootstrap and JQuery in my package.json:

"devDependencies": {
        "axios": "^0.19",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.13",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue-template-compiler": "^2.6.11"
    }

I also ran: `php artisan preset bootstrap``` before installing NPM.

Dec
09
1 month ago
Activity icon

Replied to Cartalyst/stripe-laravel: No Such Customer: Person

@wraith How do I create a record in the Stripe table? What do you mean by "show screen by error"?

Dec
08
1 month ago
Activity icon

Started a new Conversation Cartalyst/stripe-laravel: No Such Customer: Person

I'm trying to process a credit card payment and I get this error: Must provide source or customer.

I'm not sure what Stripe means by this and I've tried the solution posted here: Stripe: Must provide source or customer

public function store(Request $request)
    {
        try {
            $charge = Stripe::charges()->create([
                // 'amount' => getNumbers()->get('newTotal') / 100,
                'currency' => 'UK',
                'source' => $request->stripeToken,
                'description' => 'Thank you for your purchase.',
                'receipt_email' => $request->email,
                'customer' => $request->email, 
                'metadata' => [
                    // 'contents' => $contents,
                    'quantity' => Cart::count(),
                ],
            ]);

            Cart::destroy();

            return redirect()->route('confirmation.index')->with('success_message', 'Thank you! Your payment has been successfully accepted!');
        } catch (CardErrorException $e) {
            return back()->withErrors('Error! ' . $e->getMessage());
        }
    }

As you can see, I do have a source and a customer. If I change the $customer property to equal something like 'person', Stripe will return this: No such customer: person

What exactly am I doing wrong here?

Dec
01
1 month ago
Activity icon

Started a new Conversation Updating Cart Quantity With Crinsane/LaravelShoppingcart

I'm trying to update the quantity of items in my cart with this package: https://github.com/Crinsane/LaravelShoppingcart

Has anyone used this before?

If so, my question is, is there an easy way to increase the quantity of items in your cart? I've read the documentation for this package but there doesn't seem to be much there to help with this problem.

So far, I've only managed to update the quantity to 2 after pressing a button. What if if I want to have multiple options for increasing the quantity? So the user has the option of choosing 1, 2, 3, 4 products and so on.

// CartController.php

public function update(Request $request, $rowId)
    {
        Cart::update($rowId, 2);
        
        return back()->with('quantityIncreasedMessage', 'Product quantity has been increased.');
    }

As you can see above, the first parameter of the update method is the product id and the second parameter is the quantity.

This doesn't work:

Cart::update($rowId, ++)
// cart.blade.php

<td class="border-0 align-middle">
   <form action="{{ route('cart.update', $product->rowId) }}" method="POST">
     @csrf
  {{ method_field('PATCH') }}
  <button>+</button>
  </form>
</td>
// web.php

Route::patch('/cart/{rowId}', '[email protected]')->name('cart.update');
Nov
21
1 month ago
Activity icon

Replied to Returning Product Data In Rows Of 3

I have a solution that works quite nicely. It's very messy and it only works because I'm only retrieving 12 items. Once I remove the incline CSS it should look a lot less horrific. Here it is:

@section('content')
    <h1 class="d-flex justify-content-center" style="padding-bottom: 3rem;">Playstation Games</h1>
    @if(isset($playstationGames))
        @foreach($playstationGames as $playstationGame)
            @if($playstationGame->game_id % 3 === 0)
                <div class="text-right card" style="margin-top: -35rem; margin-left: 60rem; margin-bottom: 5rem; padding-bottom: 2rem; width: 18rem; height: 30rem;">
                    <a href="/playstation/{{ $playstationGame->slug }}"><img src="{{ asset($playstationGame->image) }}" class="card-img-top" alt="playstationgame"></a>
                    <div class="card-body">
                        <h2 class="card-text text-center">{{ $playstationGame->name }}</h2>
                        <h4 class="card-text" style="margin-right: 6.2rem; ">£{{ $playstationGame->price }}</h4>
                    </div>
                </div>
            @elseif($playstationGame->game_id === 2 || 
                    $playstationGame->game_id === 5 ||
                    $playstationGame->game_id === 8 ||
                    $playstationGame->game_id === 11)
                <div class="text-right card" style="margin-top: -30.2rem; margin-left: 35rem; margin-bottom: 5rem; padding-bottom: 2rem; width: 18rem; height: 30rem;">
                    <a href="/playstation/{{ $playstationGame->slug }}"><img src="{{ asset($playstationGame->image) }}" class="card-img-top" alt="playstationgame"></a>
                    <div class="card-body">
                        <h2 class="card-text text-center">{{ $playstationGame->name }}</h2>
                        <h4 class="card-text" style="margin-right: 6.2rem; ">£{{ $playstationGame->price }}</h4>
                    </div>
                </div>
            @else
                <div class="text-left card" style="margin-left: 10rem; width: 17.6rem; height: 30rem;">
                    <a href="/playstation/{{ $playstationGame->slug }}"><img src="{{ asset($playstationGame->image) }}" alt="playstationgame"></a>
                    <div class="card-body">
                        <h2 class="card-text text-center">{{ $playstationGame->name }}</h2>
                        <h4 class="card-text" style="margin-left: 6.2rem; margin-bottom: -2.5rem;">£{{ $playstationGame->price }}</h4>
                    </div>
                </div>
            @endif 
        @endforeach 
    @endif
@endsection

Thanks

Nov
20
1 month ago
Activity icon

Replied to Returning Product Data In Rows Of 3

@jlrdw It's not really adaptable. I've tried. He's asking for something completely different.

Activity icon

Replied to I Want To Add To Cart Without Going To An Add To Cart Page

@jlrdw

I'm not trying to understand how posting data to the cart works. I want to add to cart in my product page (game.blade.php) while simultaneously being redirected to another page (addedtocart) with the exact same view and data as my product page.

I've been following Andre Madarang's guide on Laravel but he get's directed to the cart page. I feel like this is annoying for the user so I want to do it the way I'm trying.

Activity icon

Started a new Conversation Returning Product Data In Rows Of 3

Right now I'm returning my products from the database and they're rendering one by one (one product each row). This doesn't look very professional.

How can I change this code (or my query) so that the products can render in rows of 3 instead of rows of 1?

Like this (4 products per row in this case): https://www.game.co.uk/en/games/xbox-one-games/?attributeName1=Genre&attributeValue1=4294965820&cm_mn=TopNav-_-XboxOne-_-Games-ActionAdventure#Page2

View:

@extends('layouts.products')

@section('title', '- Playstation Games')
@section('category', 'Playstation')

@section('content')
    <h1 class="d-flex justify-content-center">Playstation Games</h1>
    @if(isset($playstationGames))
        @foreach($playstationGames as $playstationGame)
            <h2>{{ $playstationGame->name }}</h2>
            <a href="/playstation/{{ $playstationGame->slug }}"><img src="{{ asset($playstationGame->image) }}" alt="playstationgame"></a>
            <h4>£{{ $playstationGame->price }}</h4>
        @endforeach 
    @endif
@endsection

Controller:

public function index()
    {   
        $playstationGames = Game::find([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);

        // returns all the games from one category
        return view('products.playstation', compact('playstationGames'));
    }   

Thanks in advance

Activity icon

Started a new Conversation I Want To Add To Cart Without Going To An Add To Cart Page

I want to add to cart without being directed to an add to cart page. So, whenever I press the add to cart button in my product page, I want to either be taken to the exact same page (but with a success message) or a different page with all the same data as my product page.

On my product page I return a product from the database based on a matching slug (typical).

However, whenever I press the add to cart button, I'm taken to my 'addedtocart' view except my product data isn't being retrieved from the database.

Here's what I have so far:

// game.blade.php

<form action="{{ route('added-to-cart') }}" method="POST">
        @csrf
        <button type="submit" class="btn btn-secondary btn-lg">Add to Cart</button>
        @isset($game)
            <input name="game_id" type="hidden" value="{{ $game->game_id }}"> 
            <input name="name" type="hidden" value="{{ $game->name }}"> 
            <input name="price" type="hidden" value="{{ $game->price }}"> 
            @if(isset($cartSuccessMessage))
                <p>{{ $cartSuccessMessage }}</p>
            @endif
        @else
            @if(isset($cartErrorMessage))
                <p>{{ $cartErrorMessage }}</p>
            @endif
        @endif
</form>
// web.php

// connects to the controllers for each platform to enable the retrieval of the games for each category
Route::get('/playstation', '[email protected]')->name('playstation'); 
Route::get('/xbox', '[email protected]')->name('xbox');
Route::get('/nintendo', '[email protected]')->name('nintendo');
Route::get('/pc', '[email protected]')->name('pc');
Route::get('/pre-order', '[email protected]')->name('pre-order');

// provides the pages for each individual product
Route::get('/playstation/{game}', '[email protected]'); 
Route::get('/xbox/{game}', '[email protected]');
Route::get('/nintendo/{game}', '[email protected]');
Route::get('/pc/{game}', '[email protected]');

Route::post('/added-to-cart', '[email protected]')->name('added-to-cart');

// simply returns the pages for these views
Route::view('/', 'landingpage')->name('landingpage');
Route::view('/cart', 'cart')->name('cart');
// addedtocart.blade.php

@extends('layouts.app')

@section('content')
    @if(isset($game))
        <h1>{{ $game->name }}</h1>
    @endif
@endsection
// CartController.php

public function store(Request $request, Game $game)
    {
        Cart::add($request->game_id, $request->name, 1, $request->price)
            ->associate('App\Product');

        $cartSuccessMessage = 'Item was added to cart successfully.';
        $cartErrorMessage = 'Oops! The cart does not seem to be working right now. Sorry!';

        return view('addedtocart', compact('cartSuccessMessage', 'cartErrorMessage', 'game')); 
    }
// AddedToCartController

public function show(Game $game)
    {   
        return view('addedtocart', compact('game'));
    }

Thanks in advance

Nov
13
2 months ago
Activity icon

Replied to Trying To Retrieve Corresponding Product Data When Clicking On Product

I thought I solved my problem. Here's how I thought I fixed it:

Instead of:

Game::create([
            'slug' => 'playstation/alien-isolation',
            'platform' => 'playstation',
            'name' => 'Alien Isolation', 
            'price' => '£19.99', 
            'description' => 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Nesciunt debitis, amet magnam accusamus nisi distinctio eveniet ullam. Facere, cumque architecto.',
            'image' => '/storage/images/playstation/alien_isolation.jpeg'
        ]);

I used the slug method:

Game::create([
            'slug' => Str::slug('Alien Isolation', '-'),
            'platform' => 'playstation',
            'name' => 'Alien Isolation', 
            'price' => '£19.99', 
            'description' => 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Nesciunt debitis, amet magnam accusamus nisi distinctio eveniet ullam. Facere, cumque architecto.',
            'image' => '/storage/images/playstation/alien_isolation.jpeg'
        ]);

This worked while I had this in my controller:

public function show($slug)
    {   
        $game = Game::where('slug', $slug)->first();
    
        return view('products.game')->with([
            'game' => $game
        ]);
    }

and this in my web.php:

Route::get('/playstation/{slug}', '[email protected]');

By 'worked', I mean it returned the data according to the corresponding slug of the page and the slug in the database. Unfortunately, as soon as I refresh the page, I get a 404.

This makes absolutely no sense to me but I am new to this.

I also don't understand how this can possibly work at all when I run my data dump method and get a response of 'null':

$game = Game::where('slug', $slug)->first();
dd($game);

Why would I be getting a 404 but only after refreshing the page? There are so many things I'm confused about here. Does anyone know why this may be?

Thanks

Nov
11
2 months ago
Activity icon

Replied to Trying To Retrieve Corresponding Product Data When Clicking On Product

@jaytee Thanks very much. I'll take a look at it at some point.

Activity icon

Replied to Trying To Retrieve Corresponding Product Data When Clicking On Product

@sinnbeck Yes I do. I get the expected slug.

I realised earlier I wasn't even passing data from the controller to the view (doh!).

That code you gave me should work because I've been successful with something similar before.

Right now, I'm able to retrieve the data I need, but only for one game and it's fetched for whatever page I'm on. So, I have the data rendered for Alien Isolation but for Mario Kart the Alien Isolation details still appear. As Alien Isolation is the first game in the database. This is the code I'm using:

// PlaystationController.php

public function show($slug)
    {   
        $game = Game::where('platform', 'playstation')->firstOrFail();
    
        return view('products.game', ['game' => $game]);
    }

// game.blade.php

@extends('layouts.app')

@section('content')
    <div class="container">
        <h2>{{ $game->name }}</h2>
        <img src="{{ asset($game->image) }}" alt="game">
        <h4>{{ $game->price }}</h4>
        <p>{{ $game->description }}</p>
    </div>
    <button type="button" class="btn btn-secondary btn-lg">Add to Cart</button>
@endsection

Of course, to fix this I've tried using this so the slug in URL get request matches the slug in the database:

// PlaystationController.php

public function show($slug)
    {   
        $game = Game::where('slug', $slug)->first();
        
        return view('products.game', ['game' => $game]);
    }

And I get this error Trying to get property 'name' of non-object

This is where I'm up to now.

Activity icon

Replied to Trying To Retrieve Corresponding Product Data When Clicking On Product

@sinnbeck But there are. The slug in the database is what's used to get me to that page in the first place. I'm confused.

I also tried this as I know there are games in the db where platform = playstation:

public function show($slug)
    {   
        $game = Game::where('platform', 'playstation')->first();
        dd($game);
        return view('products.game', ['game' => $game]);
    }

This will return the first game that's in the database that has platform = playstation. Makes sense. But when I remove the dd function, no data returns.

Activity icon

Replied to Trying To Retrieve Corresponding Product Data When Clicking On Product

@sinnbeck I get the word 'null' in orange font with a black rectangular background.

Activity icon

Replied to Trying To Retrieve Corresponding Product Data When Clicking On Product

@sinnbeck Something like this. But this specifically isn't returning my data. It isn't causing an error either though.

Activity icon

Replied to Trying To Retrieve Corresponding Product Data When Clicking On Product

That's not the problem. I'm having no trouble displaying my view from my controller. I already have this code here:

// web.php

Route::get('/playstation/{slug}', '[email protected]');

// PlaystationController.php

public function show($slug)
    {   
        return view('products.game');
    }

I just want to know how I can retrieve my product details from the database on each 'slug' page. So, when I click on the game 'Alien Isolation', it already takes me to correct page. What it doesn't do is return me the details I want (price, description, image). I've edited my post again and provided a real life example.

Activity icon

Replied to Trying To Retrieve Corresponding Product Data When Clicking On Product

@jlrdw

Yes, I have made an image a link. All the images in this app are links.

The goal is to retrieve the corresponding data for the product from the db. The pages are fine. The issue isn't with links. The issue is that I don't know how to retrieve the corresponding data for each product. Each page that extends game.blade.php when clicking on a product image should return me the product details.

Maybe I complicated my query by talking about the 'add to cart' functionality. I'll see if I can improve it.

Thanks

Activity icon

Started a new Conversation Trying To Retrieve Corresponding Product Data When Clicking On Product

I'm building a videogame store. I have my 4 categories (playstation, xbox, nintendo, pc). Each category view and controller retrieves the product details from a MySQL database. On each category page, 12 products are retrieved with their corresponding name, image and price. Here is the logic that enables this functionality (just for context, this isn't what I want to do with the other pages):

// playstation.blade.php

@section('content')
    @if(isset($playstationGames))
        @foreach($playstationGames as $playstationGame)
            <h2>{{ $playstationGame->name }}</h2>
            <a href="{{ $playstationGame->slug }}"><img src="{{ asset($playstationGame->image) }}" alt="playstationgame"></a>
            <h4>{{ $playstationGame->price }}</h4>
        @endforeach 
    @endif
@endsection

// PlaystationController.php

public function index()
    {   
        $playstationGames = Game::find([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);

        return view('products.playstation')->with([
            'playstationGames' => $playstationGames
        ]);
    } 

When I click on one of the images, I want to be directed to a page for that product. For example, if I click on the image for Mario Kart, I want to be directed to a page with the data for that game (corresponding image, name, price, description). These details are already in the database. I know how to fetch these as an array. But I want to fetch these individually and for each one to correspond to the page (slug) I'm visiting.

How can I achieve this?

Edit: Here's an example of what I want: https://laravelecommerceexample.ca/shop

When you click on the image for 'laptop 1', you are taken to it's corresponding 'slug page' (I've already achieved this). What I don't know how to do is return the unique description, price, image etc as displayed when you click on the product image on this website. All I've managed to do is return my blade template from my slug link.

As you can see in the above code. I know how to loop through the products and return them all. I don't know how to return one that matches the corresponding slug of the page.

Thanks

Nov
10
2 months ago
Nov
09
2 months ago
Activity icon

Replied to Undefined Variable From The View

@nakov

I've managed to retrieve the games but only form my routes file

// web.php
// connecting to model
use App\Game;

// retrieving games from db
Route::get('/playstation', function() {
    $playstationGames = Game::find([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);

    return view('products.playstation')->with([
        'playstationGames' => $playstationGames
    ]);
})->name('playstation');

// playstation.blade.php
@section('content')
    @if(isset($playstationGames))
        @foreach($playstationGames as $playstationGame)
            <h2>{{ $playstationGame->name }}</h2>
            <a href="{{ $playstationGame->slug }}"><img src="{{ asset($playstationGame->image) }}" alt="playstationgame"></a>
            <h4>{{ $playstationGame->price }}</h4>
        @endforeach 
    @endif
@endsection

I have no idea why I can get it to work in routes but not my controller. Is it ok to do it like this? The games are also rendering twice which is weird.

Activity icon

Replied to Undefined Variable From The View

@nakov I accidentally posted the wrong code from another project that works. I've edited the code in the previous comment.

Activity icon

Replied to Undefined Variable From The View

@nakov

This is the relevant code I have in my view:

Route::view('/playstation', 'products/playstation')->name('playstation');
Route::get('/products/playstation', '[email protected]')->name('game');

public function index()
    {   
        // gets the playstation games as an array by their id's
        $playstationGames = Game::find([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);

        return view('products/playstation')->with([
            'playstationGames' => $playstationGames
        ]);
    }

As long as I'm not using the $playstationGame property, the view will return as normal.

Activity icon

Replied to Undefined Variable From The View

@nakov Just tried this but still get the same error.

@sinnbeck Sorry, what's dd()?

@manelgavalda I've tried those commands. Still no luck.

Activity icon

Started a new Conversation Undefined Variable From The View

I've ran this exact same code before in another project and it has worked so I'm not sure what's going on here.

I'm getting this error:

Undefined variable: playstationGames (View: /home/harri/.config/composer/vendor/bin/projects/new_project/resources/views/products/playstation.blade.php)

Here is my code from the view:

@foreach($playstationGames as $playstationGame)
    <h2>{{ $playstationGame->name }}</h2>
    <a href="{{ $playstationGame->slug }}"><img src="{{ asset($playstationGame->image) }}" alt="playstationgame"></a>
    <h4>{{ $playstationGame->price }}</h4>
@endforeach 

Here is my code from the controller:

public function index()
    {   
        // gets the playstation games as an array by their id's
        $playstationGames = Game::find([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);

        return view('playstation')->with([
            'playstationGames' => $playstationGames
        ]);
    }
Nov
03
2 months ago
Activity icon

Replied to Laravel 6.0: Resetting Password: 404 Not Found

@jove @siangboon @munazzil

Works. Just needed to change the APP_URL variable in .env to http://localhost:8000 instead of http://localhost. Thanks for your help and sorry for the late reply.

Oct
26
2 months ago
Activity icon

Replied to Rendering Images From A MYSQL Database

@sinnbeck @ap3twe

It does! Thank you both.

Oct
25
2 months ago
Activity icon

Replied to Rendering Images From A MYSQL Database

When I say it holds the path, I mean the corresponding path that I wrote in my database table. I'm not sure if it actually holds the path to the image itself. So, no, I don't think it includes the image file which is probably the problem.

I've read that you shouldn't store the actual image in the database. Just the corresponding path to it.

Right now $playstationGame->image will only output this:

storage/images/callofduty.jpeg

The path I wrote in the database.

Oct
24
2 months ago
Activity icon

Replied to Rendering Images From A MYSQL Database

It does load! I'm not sure why it skips the app and public folders. I can now retrieve the images from my app with this:

<a href=""><img src="{{ asset('storage/images/callofduty.jpeg') }}" alt="product"></a>

I'm still not sure how to retrieve them from the database though. To retrieve a name I'm doing this:

<h2>{{ $playstationGame->name }}</h2>

and it's working.

But to retrieve an image I do the same thing and nothing appears except the name of the path (because that's what's stored in the database as a text data type).

<h4>{{ $playstationGame->image }}</h4>
Activity icon

Replied to Rendering Images From A MYSQL Database

I haven't used this:

request('file')->store('images')

All I've done is, seed the paths of the images in the database using a seeder. Could this be why I'm having trouble?

Activity icon

Replied to Rendering Images From A MYSQL Database

Sorry, I don't know what you mean. Use the asset helper where exactly? It's being used in the HTML.

Activity icon

Replied to Rendering Images From A MYSQL Database

When I run that I get this:

The "public/storage" directory already exists
Activity icon

Replied to Rendering Images From A MYSQL Database

It was the wrong path anyway. I'm typing this path and getting a 404:

http://localhost:8000/storage/app/public/images

However, I've checked and this where my images are stored.

Activity icon

Replied to Rendering Images From A MYSQL Database

Oops! Forgot to add this:

<a href=""><img src="{{ asset('storage/images'.$playstationGame->image) }}" alt="product"></a>
Activity icon

Started a new Conversation Rendering Images From A MYSQL Database

I'm building a shopping cart system and I'm trying to retrieve the images for each product from the database. However, I'm not sure how to do this.

I have the images stored as their file path names in the database as this is the recommend way of doing things (instead of a BLOB type).

Here's an example of an image I'm trying to render:

/storage/app/public/images/callofduty.jpeg

I've checked and the image is definitely in that directory. I seeded it in my table as a text data type and not a string data type. I'm not sure if this is correct.

The output rendered on my app is currently just the path of the image. Not the image itself.

How can I render the actual image on my page and not just the file path?

Thank you

Oct
23
2 months ago
Activity icon

Replied to Trying To Retrieve Multiple Data Values With Eloquent

That'll return all the games I want to return but It'll also return the key as well as the value. I only want the value to be returned. Sorry, I should have specified this in the description. The value helper will ensure that only the value is returned. That's why I included it and it's also why I didn't use the get method, because I'd tried it before.

With your method, the output is this:

{"name":"Call of Duty Advanced Warfare"}
{"name":"Dishonored 2"}
{"name":"Dying Light"}

I want this:

Call of Duty Advanced Warfare
Dishonored 2
Dying Light

Ideally, I'd try and use the get method with the value method but Laravel doesn't seem to allow me.

Thanks

Activity icon

Started a new Conversation Trying To Retrieve Multiple Data Values With Eloquent

I have a table called Games. I'm trying to retrieve all the games with the platform column name of 'playstation'.

This is my current code:

// GameController.php

public function index()
    {   
        $playstationGames = Game::orderBy('name', 'asc')->take(8)->value('name'); 

        return view('playstation')->with([
            'playstationGames' => $playstationGames
        ]);
    }

// playstation.blade.php

<h2>{{ $playstationGames }}</h2>

The first 8 values in the table have the platform name of playstation so that's why I'm using take(8).

However, it's only returning the first name and not the other 7.

What method do I have to add to make it return all 8?

I've also tried this:

public function index()
    {   
        $playstationGames = Game::where('platform', 'playstation')->value('name'); 

        return view('playstation')->with([
            'playstationGames' => $playstationGames
        ]);
    }

Thanks