Shoken

Shoken

Member Since 2 Weeks Ago

Experience Points 530
Experience Level 1

4,470 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 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

21 Feb
1 day ago

Shoken started a new conversation How To Make A Page Accessible Only By Clicking On A Button?

Title is confusing, I understand. Here's what's happening: my user has a view on their cart where they can review which items they are buying. On that view, they can click a button that says "Go to payment methods" and open another view where they can insert their data.

However, I do not want that payment page to be accessible from the URL. The user should only get there by using that button, and not in any other way.

I've tried using sessions but the basic knowledge I have is probably not enough. This is a cardinal part for security (my project isn't really going live, it's for uni), and I wanted to know if there was a standarized better way that I'm not aware of.

20 Feb
2 days ago

Shoken left a reply on Class "Input" Not Found.

Using old('product') fixed the problem, and yes I did put "use" on top of the controller. Guess we will never know what was causing that error.

19 Feb
3 days ago

Shoken started a new conversation Class "Input" Not Found.

This is the error I get:

Class 'Input' not found (View: C:\MAMP\htdocs\eCommerce\resources\views\back_end\createProduct.blade.php)

The line with the error is this one:

 Form::text('name', Input::old('nameProduct'),['class' => 'form-control','required' => 'required']) }}

Yes, I know I should've inserted Input in the aliases in the config/app.php file, and I have done so. In the aliases , there is:

'Input' => Illuminate\Support\Facades\Input::class,

So I have no idea what I am doing wrong. I'm doing this project with another guy and he doesn't get this error, while I do, and our Git version is EXACTLY the same. We're totally lost here,

Shoken left a reply on Using AJAX With Laravel For Simple Operations

I wanted to give this issue some closure, so people who have the same problem and googled it (hey there!) will find a solution. I read what jlrdw linked and also followed click's advice for CSRF tokens. In the end, I managed to make it work with this code:


 <script>

// "cart" is the ID of my "Add to Cart" button.

                $('#cart').click(function(){
                    $.post("/addtocart",
                        {
//Gets stuff from the form  (e.g.: number of products to add)

                            number: document.getElementById("number").value,
                            itemid: $('#hiddenID').text(),
                        },
                        function() {

//Changes text on the button and disables it, if the function returns success from PHP.

                            document.getElementById("cart").innerHTML = "Added!";
                            document.getElementById("cart").disabled = true;
                    }

                    ) });


            </script>

18 Feb
4 days ago

Shoken started a new conversation Using AJAX With Laravel For Simple Operations

Ok, so my goal is very simple: when the user clicks on the button "Add to Cart", the item gets added to the cart without reloading the page. To do this, I know I have to use AJAX in my Laravel environment.

Here is my HTML button:

<button id="cart" class="btn-round">Aggiungi al carrello</button> 

This is my script:

<script>
        $("#cart").click(function()
        {
            $.ajax(
                {
                type: "POST",
                url: '/addtocart',
                data: { itemid: 2 },
                }
                )
        });
    </script>

I have added this route to my web:

Route::post('/addtocart', '[email protected]');

And lastly, this is my Controller:

class CartController extends Controller
{
    //

    public function add($itemid){

        if (Auth::guest())
        {return redirect('/login');}
        else{

            $userid=Auth::user()->id;
            $item=Product::find($itemid);

            $cartitem=new Cart;
            $cartitem->user_id=$userid;
            $cartitem->product_variant_id=$itemid;
            $cartitem->totalprice=$item->normalPrice;

            $cartitem->save();

            return redirect('/products/'.$itemid);


        }
    }
}

As you can see I have hardcoded some values to test stuff, but it does not work. I don't get any errors so I think the Controller is actually never called. The route should be enough, right? Or maybe there are some syntax errors in my AJAX code? I find the online documentation for AJAX extremely confusing.

14 Feb
1 week ago

Shoken left a reply on @foreach Does Nothing, Even If I Do Have Objects.

@CLICK - You were totally on point, and so fast too! I was under the impression that ->take(n) could substitute ->get(), but I re-read the documentation and boy was I wrong. The objects I were passing were query objects!

Thank you so much. I had a massive misunderstanding of a basic function, so I do not regret asking even if that wasn't the smartest question :p

Shoken started a new conversation @foreach Does Nothing, Even If I Do Have Objects.

Ok so what is happening is very weird. What happens is, I have an HTML pane view defined with multiple categories. In this case, my HTML looks like this:

<li role="presentation"><a href="#game-com" aria-controls="special" role="tab" data-toggle="tab"><i class="flaticon-gamepad-1"></i>Game Console <span>{{$data['games']->count()}}</span></a></li>

Now done below I have defined the content of such panes, as such:

<!-- Game Console -->
                    <div role="tabpanel" class="tab-pane fade" id="game-com">
               
                        <!-- Items -->
                        <div class="item-col-5">
                            <!-- Product -->
                            @foreach($data['games'] as $game)
                                <div class="product">
                                    <article> <img class="img-responsive" src="images/item-img-1-1.jpg" alt="" >
                                        <!-- Content -->
                                        <span class="tag">{{$game->category}}</span> <a href="/products/{{$game->id}}" class="tittle">{{$game->name}}</a>
                                        <!-- Reviews -->
                                        <p class="rev"><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i> <i class="fa fa-star-o"></i> <span class="margin-left-10">{{$game->reviewsnumber}} Recensioni</span></p>
                                        <div class="price">{{$game->normalPrice}} </div>
                                        <a href="/products/{{$game->id}}" class="cart-btn"><i class="icon-basket-loaded"></i></a>
                                    </article>
                                </div>
                            @endforeach
                        </div>
                    </div>

As you can see, those are just little boxes that contain all the info I need (I had a template and simply edited what I needed). However, nothing shows up! I tried doing

dd($data['games']->first());

Right before the @foreach and it does show at least one element! But nothing appears.

I also tried putting

<p> TEST </p>

Inside the @foreach loop but those do not appear, and even if I go see the Source code of the page, they are not there! Also the {{$data['games']->count()}} on the tab pane works as intended, as it shows the correct number of items I have.

So the items are definitely there and correctly passed to the view, but I simply can't get them to show up. What am I doing wrong?

11 Feb
1 week ago

Shoken left a reply on Form Submit Not Working

Thanks everyone for the answers. I've tried each and everyone of them.

I fixed it, but none of those were the answer. Turns out, I had an open tag in my HTML even before I started writing the form in Laravel. So they were kind of innested forms..? I'm not really sure, but I can see why it wasn't working.

Oh also actually I had to change the routing to lowercase message, that was also necessary.

I lost 4 hours on this. In case anyone else has this problem, please please please check your HTML.

Thanks again!

Shoken left a reply on Form Submit Not Working

@MUNAZZIL - I have, that use is already in place. My message model is empty as I created that with artisan together with its migration.

However, I feel like the controller is not the issue, because even if I simply put "return 123" in the store function, it still doesn't work. I feel like the issue is in the Routing or something, but I just can't get it to work.

Shoken left a reply on Form Submit Not Working

Here is my web.php:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', '[email protected]');
Route::get('/about','[email protected]');


Auth::routes();

/*
Route::get('/home', '[email protected]')->name('home');*/




Route::get('/admin',function (){
    return view('back_end.index');
});

Route::get('/admin',function (){
    return view('back_end.dashboard');
});


Route::get('/admin/users', '[email protected]');
Route::resource('Message','MessageController');

And I had no output with dd($request). Or at least, I don't know how to get it. Simply going with php artisan serve again produced nothing, and neither did clicking on the button.

Shoken left a reply on Form Submit Not Working

@MUNAZZIL - I get nothing new. Everything's just as it was before: I think the controller is never even called.

Shoken started a new conversation Form Submit Not Working

I've been stuck with this issue for serveral hours, so hopefully some of you can help. Thanks in advance.

The issue is simple: when I click the form's submit button, nothing happens. Like, literally nothing. No errors, anything. Before starting developing the form I had created the Message model by doing

php artisan make:model Message --resource

Thus I have the methods create, store etc.. already done and ready (thanks artisan!). In my route web.php route file, I have:

Route::resource('Message','MessageController');

This should automatically link all the methods, right?

Anyway, my form is:

{!!  Form::open(['action' => '[email protected]', 'method' => 'POST']) !!}
                                    <ul class="row">
                                        <li class="col-sm-6">
                                            <label>{{Form::label('name','Name')}}</label>
                                                {{Form::text('name', '', ['class' => 'form-control'])}}
                                        </li>
                                        <li class="col-sm-6">
                                            <label>{{Form::label('email','Email')}}</label>
                                                {{Form::text('email', '', ['class' => 'form-control', 'placeholder' => 'Your email'])}}
                                        </li>
                                        <li class="col-sm-12">
                                            <label>{{Form::label('message','Message')}}</label>
                                                {{Form::textarea('message','', ['class' => 'form-control'])}}
                                        </li>
                                        {{Form::submit('Submit', ['class' => 'btn-round'])}}

                                    </ul>
                                    {!! Form::close() !!}

and my [email protected] looks like this:

 public function store(Request $request)
    {
        $this -> validate($request, [
            'name' => 'required',
            'email' => 'required',
            'message' => 'required'
            ]
            );

        $message = new Message();
        $message -> name= $request -> input('name');
        $message -> email= $request -> input('email');
        $message -> text= $request ->input('text');
        $message -> user_id = Auth::user()->id;

        $message->save();

        return redirect('/');
    }

The controller just doesn't seem to work because even if I cut validation, nothing happens. I have no clue what I'm doing wrong!

10 Feb
1 week ago

Shoken left a reply on Where To Check If An User Is Logged In?

@TYKUS - I had mistakenly copied

use Illuminate\Support\Facades\View;

in the view composer... now it works perfectly! Thank you!

Shoken left a reply on Where To Check If An User Is Logged In?

Alright so I copied the View::Composer function in AppServiceProvider's boot and that other code in the new class. However I am now getting the error:

Argument 1 passed to App\Http\View\Composers\CartComposer::compose() must be an instance of App\Http\View\Composers\View, instance of Illuminate\View\View given

I am... pretty lost here

Shoken started a new conversation Where To Check If An User Is Logged In?

Hey there, I've been using your advice and View::sharing all of my important data to all views. However, there is one issue I have encountered.

This code:

if(!Auth::guest()){
            $user=Auth::user()->id;
        }
        else $user=0;
        $temp=DB::select('query');


        View::share('cartnumber', count($temp));
        View::share('cartitems', $temp);

doesn't work when put in AppServiceProvider. Or better, it always sets $user=0, even if I am logged in. I thought it is because AppServiceProvider's boot function executes before the site checks if someone is logged in.

I then tried to use a BaseController with a construct function but that doesn't work either. The only solution that seems to work correctly is putting the code in every single Controller for every view! That actually works, which kind of confirms my theory.

But is there anywhere I can put this code without having to copy/paste it in every single Controller? Thanks in advance!

08 Feb
2 weeks ago

Shoken left a reply on Passing The Same Variables To Multiple Views Over And Over Again

@SNAPEY - This is probably a more elegant solution, thank you!

Shoken left a reply on Passing The Same Variables To Multiple Views Over And Over Again

@tomopongrac it works now! I made a mistake when calling for those variables.

Before, I returned the views with the method with(). That allowed me to call the variables directly with $categories and such.

Now I have to do $data['categories'] so it can work. My understanding is this has to do with the fact that I'm working with an array and no longer an object, but I might be wrong.

Anyway, in case anyone else needs this, I'm going to leave this here. :) Thanks for the help.

Shoken left a reply on Passing The Same Variables To Multiple Views Over And Over Again

@TOMOPONGRAC - I get a very long dump of the data in the DB. Not sure if I should post it all here, but here's a fraction of it for reference:

array:2 [ "main_menus" => Illuminate\Database\Eloquent\Collection {#170 #items: array:3 [ 0 => App\MainMenu {#171 #connection: "mysql" #table: "main_menus" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:6 [ "id" => 1 "created_at" => null "updated_at" => null "name" => "Homepage" "URL" => "/" "Order" => 1 ] #original: array:6 [ "id" => 1 "created_at" => null "updated_at" => null "name" => "Homepage" "URL" => "/" "Order" => 1 ]

.... etc...

Shoken left a reply on Passing The Same Variables To Multiple Views Over And Over Again

@TOMOPONGRAC - That seems exactly what I need, but I am a bit confused on the values of 'key' and 'value'. Now I wrote, in the class AppServiceProvider:

''' public function boot() {

    $menu = MainMenu::OrderBy('Order', 'asc')->get();
    $cat = Category::OrderBy('sortOrder', 'asc')->get();

    $data = array(
        'main_menus' => $menu,
        'categories' => $cat,
    );

    View::share('data', $data);
}

'''

But this does not seem to work, as categories is an undefined variable.

Shoken left a reply on Passing The Same Variables To Multiple Views Over And Over Again

@TOMOPONGRAC - Nevermind what I posted earlier -- it worked! Thank you so much. This framework is so efficient and clean.

Shoken left a reply on Passing The Same Variables To Multiple Views Over And Over Again

@TOMOPONGRAC - Thank you! This seems exactly what I need. I do feel a little confused on what 'key' and 'value' mean, though.

Should I put ('data', $data) in my case? Because that doesn't seem to work.

Shoken started a new conversation Passing Variables To The Same View Over And Over Again

Hey everyone, I've recently started using Laravel for a university project. It is AMAZING.

I have one issue I haven't been able to solve myself, though. Basically I have a main nav menu stored in the file main.blade.php.

This file is extended by all the other views, including "index.blade.php" and "about.index.php".

Now, when returing index through my FrontEndController, I just prepare an array of variables and return it with the view in order to dinamically generate my menus and categories. Basically my function looks like this:

''' public function index() { $menu = MainMenu::OrderBy('Order', 'asc')->get(); $cat = Category::OrderBy('sortOrder', 'asc')->get();

    $data = array(
        'main_menus' => $menu,
        'categories' => $cat,
    );

    return view('front_end.index')->with($data);

}

'''

Note that all these variables are used by the menu, not the content. Now I've started working on "about.index.php" and I noticed that I have to send the same $data array all over again in order to prepare the menu once more. So I basically need to send the same array over and over again for all the views.

This seems redundant and repetitive, and I feel like I am missing something. Is there a better way to do this?