heizenberg

heizenberg

Member Since 4 Years Ago

Experience Points 2,230
Experience Level 1

2,770 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-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.

10 Aug
3 years ago
06 Aug
3 years ago

heizenberg left a reply on Chrome Extension

@Snapey yup. I've seen it in JeffreyWay chrome extension :D

heizenberg left a reply on Chrome Extension

@ralee Thank you. But I already have that two extensions installed plus the JSON Formatter.

heizenberg left a reply on Chrome Extension

I also want to download and learn how to use it.

heizenberg left a reply on Chrome Extension

Yep, chrome extension. Just want to know the name :)

heizenberg started a new conversation Chrome Extension

A quick question about @JeffreyWay chrome extension.

Thanks!

27 Jul
3 years ago

heizenberg started a new conversation Vuejs And Typeahead

I've watched the (https://laracasts.com/series/search-as-a-service/episodes/3)[lesson] about twitter typeahead here at laracasts and I just want to know how can I get my typeahead souce when working with laravel eloquent.

This is all i got

<input type="text" class="form-control" id="typeahead" v-model="query">
<script>
            new Vue({
                el: '#app',

                data: {
                    query: '',
                    users: [],
                },

                methods: {
                    searchSomething: function() {
                        this.$http.get('api/search/' + this.query, function(results) {
                            this.users = results;
                        });
                    },
                },

                ready: function() {
                    $('#typeahead').typeahead(null, function() {
                        source: // searchSomething?
                    });
                },
            });
</script>
20 Jul
3 years ago

heizenberg started a new conversation Laravel + Vuejs/Vuefire + Firebase

Hi @JeffreyWay

Can you please make a screencasts about Laravel + Vuejs/Vuefire + Firebase

26 Jun
3 years ago

heizenberg started a new conversation Laravel ModelFactory Seeding Pivot Table

Hi, I need help on how to seed many-to-many relationship using ModelFactory in Laravel. In my ModelFactory, I have the default factory of user and here are the products and cart factory:

ModelFactory

$factory->define(App\Product::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'image' => $faker->imageUrl(600, 480),
        'price' => $faker->randomFloat(2, 100, 500)
    ];
});

$factory->define(App\Cart::class, function (Faker\Generator $faker) {
    return [
        'user_id' => App\User::lists('id');
    ];
});

and then I have this in my DatabaseSeeder

public function run()
    {
        App\User::truncate();
        App\Cart::truncate();
        App\Product::truncate();

        DB::table('cart_product')->truncate();

        factory(App\Product::class, 10)->create();
        factory(App\User::class, 10)->create()->each(function($u)
        {
            $u->cart()->save(factory(App\Cart::class)->create()->each(function($c)
            {
                $ids = App\Product::lists('id')->toArray();
                $c->products()->sync($ids);
            }));
        });
    }

Here are my models relationships: User

public function cart()
{
    return $this->hasOne(Cart::class);
}

Cart

public function user()
{
    return $this->belongsTo(User::class);
}

public function products()
{
    return $this->belongsToMany(Product::class);
}

Here are my tables:

carts

id
user_id

cart_product

id
cart_id
product_id
quantity

When I run php artisan db:seed I'am getting this error

[Symfony\Component\Debug\Exception\FatalThrowableError]

  Type error: Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, boo
lean
  given, called in ...\...\...\...\Cashier\database\seeds\DatabaseSeeder.php on line 27
22 Jun
3 years ago

heizenberg started a new conversation Laravel And Browserify

Hi, I would like to know how to require javascipts files that are downloaded via npm (node_modules) folder.

This is the gulpfile:

var elixir = require('laravel-elixir');

/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Sass
 | file for our application, as well as publishing vendor resources.
 |
 */

elixir(function(mix) {
    mix
        .sass('app.scss')
        .browserify('app.js');
});

In the app.js I have this code:

var jquery = require('jquery');
var jquery-ui = require('jquery-ui');
var bootstrap = require('bootstrap-sass');

And it's not working.

21 Jun
3 years ago

heizenberg started a new conversation Laravel NPM Install

Hi,

Need help about the node_modules sub-directories. Last time I use Laravel when I use npm install I get a new folder named node_modules with sub-directories:

.bin/
bootstrap-sass/
gulp/
laravel-elixir/

But now when I use npm install I get alot more sub-directories inside node_modules

.bin/
abbrev/
accepts/
accord/
acorn/
after/
align-text/
alphanum-sort/
and more...

Why is that? Thanks

14 Jun
3 years ago

heizenberg left a reply on Laravel And JQuery Sortable Returns Null

@MaverickChan in the meta tag of my html docs.

<meta name="csrf-token" content="{{ csrf_token() }}">

And then in my js file I have these:

$(function() {
    $.ajaxSetup({
        headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    // More js codes written here...
});

I get a 200 response and got null

heizenberg started a new conversation Laravel And JQuery Sortable Returns Null

I've search for about an hour or two to find an answer to my problem of why jQuery returns null using toArray/serialize. I find alot of answers here in SO but still don't work for me.

index.blade.php

<div class="container">
    <div class="row">
        <div id="sortable">
            @foreach($items as $item)
            <div class="col-md-3">
                <div class="bg-gray ui-sortable-handle" id="item-{{ $item->id }}">Item {{ $item->id }}</div>
            </div>
            @endforeach
        </div>
    </div>
</div>

app.js

$(function() {
    $("#sortable").sortable({
        cursor: "move",
        update: function(event, ui) {

            var items = $(this).sortable('serialize', {
                attribute: "id",
            });

            $.ajax({
                url: '/change/position',
                data: items,
                type: 'POST'
            });
        }
    }).disableSelection();
});

ItemsController

public function movePosition()
{
    dd(request()->input('items'));
}

Checking the Chrome Dev Tool result is null.

17 Nov
3 years ago

heizenberg started a new conversation Elegant Website Thumbnail

Hi guys! Do you know where @jeffreyway get his custom thumbnail for every video he release here in laracasts? Did he create it himself or he use some sort of service or something? :D

heizenberg left a reply on Sublime Text 3 Match Tabs Color/Background Color

Found a solution, edited the images in the assets folder and match the facebook theme color. :D

04 Sep
3 years ago

heizenberg started a new conversation Sublime Text 3 Match Tabs Color/Background Color

Hello guys, how can I match color/background color of sublime text 3 tabs. I'm using Material Theme.

23 Aug
3 years ago

heizenberg started a new conversation Laravel 5.1 Validation Rules Digits/digits_between

I am trying to validate my form using Laravel 5.1 FormRequest and in my FormRequest rules() method I am validating the input field to be a digits_between:1,5, When I test my form and input 1 I'm getting an error The width must be between 1 and 5 digits.

I try using normal Request and dd($request->all()) and the result from my form input is a string:

array:2 [
    "_token" => "Md7Q8s6iAUw8JytippV5dPV5FIgKX7OeVKbhLpZm"
    "width" => "1"
]

How can I convert the string "1" to integer 1 to make my FormRequest pass?

Here is my HTML Code:

{!! Form::open('route' => 'somenamedroute') !!}
    {!! Form::number('width',  1, ['min' => 1, 'max' => 5, 'class' => 'form-control']) !!}
{!! Form::close() !!}

I think a have seen it in a tutorial by @JeffreyWay here at Laracasts but I forgot what is the title of the tutorial.

heizenberg left a reply on How To Convert My Input To Integer

@mstnorris That isn't what you asked originally. You asked to convert a string to an integer.

In your form request, cast the string version of the input to an integer.?

How? Please give an example

heizenberg left a reply on How To Convert My Input To Integer

@mstnorris Yup.

That's not what I am looking for I think. What I need is when user input to a field with an integer the result is actually a string.

array:1 [
    "width" => "20"
]

Ofcourse that FormRequest will fail. I can't convert it to my controller store method because the FormRequest will automatically fire when my input is invalid.

heizenberg left a reply on How To Convert My Input To Integer

@mstnorris I read the Laravel Attribute Casting: http://laravel.com/docs/5.1/eloquent-mutators#attribute-casting. The examples are all in the model. How can I casts the input in my FormRequest? Sorry I am a Noob :D

heizenberg left a reply on How To Convert My Input To Integer

I am using LaravelCollection and this is my form input:

{!! Form::number('width',  1, ['min' => 1, 'max' => 5, 'class' => 'form-control']) !!}

I am using FormRequest So I think that is not what I'm looking for? My FormRequest will validate the form input and the form input is string instead of a digits

heizenberg left a reply on How To Convert My Input To Integer

Hello @mstnorris Can you tell me what and how to use the casts?

heizenberg started a new conversation How To Convert My Input To Integer

I'm having problem validating Laravel 5.1 Form Request. I have Input number and I am trying to validate it if it is a digit.

My FormRequest

public function rules()
{
    return [
        'width' => 'required|digits_between:1,5'
    ];
}

dd Result:

array:2 [
    "_token" => "Md7Q8s6iAUw8JytippV5dPV5FIgKX7OeVKbhLpZm"
    "width" => "20"
]

I check the result but the width return a string. How can I convert it to integer. I see that JeffreyWay did that in a tutorial and I forget what tutorial it is.

The result should be:

array:2 [
    "_token" => "Md7Q8s6iAUw8JytippV5dPV5FIgKX7OeVKbhLpZm"
    "width" => 20
]
22 Aug
3 years ago

heizenberg started a new conversation Form Model Binding Not Working On Input File

Hello why form model binding not working on input file?

{!! Form::model($collection, ['file' => true, 'method' => 'PATCH', 'route' => ['named.route', $collection->id]]) !!}

<div class="form-group{{ $errors->has('image_path') ? ' has-error' : '' }}">
                            {!! $errors->first('image_path', '<label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> :message</label>') !!}
                            {!! Form::file('image_path', ['class' => 'form-control']) !!}
                        </div>
{!! Form::close() !!}
21 Aug
3 years ago

heizenberg left a reply on Laravel 5.1 And SweetAlert Ajax Token For Deleting A Product

Hello again @bimalshah72 :D

I'm getting MethodNotAllowedHttpException.

BTW Thank you for always helping me. Hehehe

heizenberg started a new conversation Laravel 5.1 And SweetAlert Ajax Token For Deleting A Product

Hello how can I get the token for deleting a product using SweetAlert and Ajax In Laravel 5.1

@foreach($products as $product)
    <tr>
        <td>{{ $product->name }}</td>
        <td>{{ $product->description }}</td>
        <td>{{ $product->updated_at->diffForHumans() }}</td>
        <td>{{ $product->created_at->diffForHumans() }}</td>
        <td>
            <div class="btn-group">
                {!! Form::open(['method' => 'DELETE', 'route' => ['dashboard.window-products.destroy', $product->id]]) !!}
                <a href="{{ route('dashboard.window-products.show', [$product->slug]) }}" class="btn btn-xs btn-default btn-flat"><i class="fa fa-eye"></i></a>
                <a href="{{ route('dashboard.window-products.edit', [$product->slug]) }}" class="btn btn-xs btn-default btn-flat"><i class="fa fa-edit"></i></a>

                <button type="button" class="deleteproductModal btn btn-xs btn-default btn-flat"
                        data-toggle="modal"
                        data-product_token="{{ csrf_token() }}"
                        data-product_name="{{ $product->name }}"
                        data-product_destroy_route="{{ route('dashboard.window-products.destroy', $product->id) }}">
                    <i class="fa fa-trash"></i>
                </button>

                {!! Form::close() !!}
            </div>
        </td>
    </tr>
@endforeach

<script>
    $('button.deleteproductModal').click(function()
    {
        var productRoute = $(this).attr("data-product_destroy_route");
        var productName = $(this).attr("data-product_name");
        var productToken = $(this).attr("data-product_token");

        deleteproduct(productRoute, productToken, productName);
    });

    function deleteproduct(productRoute, productToken, productName)
    {
        swal({
            title: "Window product Deletion",
            text: "Are you absolutely sure you want to delete " + productName + "? This action cannot be undone." +
            "This will permanently delete " + productName + ", and remove all collections and materials associations.",
            type: "warning",
            showCancelButton: true,
            closeOnConfirm: false,
            confirmButtonText: "Delete " + productName,
            confirmButtonColor: "#ec6c62"
        }, function()
        {
            $.ajax({
                type: "DELETE",
                url: productRoute,
                headers: { 'X-CSRF-TOKEN' : productToken }
            }).done(function(data)
            {
                swal("Window Product Deleted!", productName + " Window Product was successfully delete.", "success");
            }).error(function(data)
            {
                swal("Oops", "We couldn't connect to the server!", "error");
            });
        });
    }
</script>

heizenberg left a reply on Show SweetAlert In Laravel Failed Authentication

@veve286

Why I'm getting only string sweetAlert("Oops...", "Something went wrong!", "error"); my sweeralert script is included in my master page

heizenberg started a new conversation Show SweetAlert In Laravel Failed Authentication

Hello how can I show the SweetAlert when failed authentication in Laravel 5.1?

I Override the AuthenticatesUser Traits postLogin and right before the return redirect I put the sweetalert code

alert()->error('There were some problems with your input.', 'Whoops!')->persistent('Close');

But the sweertalert modal is not showing

09 Aug
4 years ago

heizenberg left a reply on Laravel 5.1 Reusable Slug

@Code4Coffee

I still don't understand what file and what line I am setting the name same as slug. Sorry I'm a noob. :/

heizenberg left a reply on Laravel 5.1 Reusable Slug

@Code4Coffee

I don't understand what line should I change. Hehehe.

heizenberg left a reply on Laravel 5.1 Reusable Slug

@Code4Coffee

I tried your suggested pseudo code and ended up like this:

<?php

namespace App\Traits;

trait Sluggable
{
    public function slug($title, $unique)
    {
        $slug = str_slug($title . '-' . $unique);

        if (static::whereSlug($slug)->exists())
        {
            return $this->slug($title, $unique + 1);
        }

        return $this->attributes['slug'] = $slug;
    }
}

Then use it on my model like this:

use Sluggable;

    protected $fillable = ['name', 'description'];

    public function setNameAttribute($name)
    {
        $this->attributes['name'] = $name;

        if (! $this->exists)
        {
            $this->attributes['name'] = $this->slug($name, '');
        }
    }

In my database, I only have id, name, slug, description and laravel timestamp and when I tried saving the name and slug column are the same. LOL

heizenberg left a reply on Laravel 5.1 Reusable Slug

Hello @Code4Coffee

Can you provide an example for me to work with? Thanks!

heizenberg left a reply on Laravel 5.1 Reusable Slug

Hi @kayyyy I already have the code that is working and I understand. I just need it to make reusable. I know reinventing the wheel is not good but to a newbie like me, I like reinventing the wheel for future ref. Hehehe. BTW Thanks!

heizenberg started a new conversation Laravel 5.1 Reusable Slug

Hello how can I make the unique slug logic reusable in my project. I have a method for creating a unique slug in my Product model and I want to use that same logic in my other model here:

/**
     * Set the name attribute and automatically the slug
     *
     * @param string $name
     */
    public function setNameAttribute($name)
    {
        $this->attributes['name'] = $name;

        if(! $this->exists)
        {
            $this->setUniqueSlug($name, '');
        }
    }

    /**
     * Recursive routine to set a unique slug
     *
     * @param string $name
     * @param mixed $extra
     */
    public function setUniqueSlug($name, $extra)
    {
        $slug = str_slug($name . '-' . $extra);

        if (static::whereSlug($slug)->exists())
        {
            $this->setUniqueSlug($name, $extra + 1);

            return;
        }

        $this->attributes['slug'] = $slug;
    }
03 Aug
4 years ago

heizenberg started a new conversation View Composer

Hello guys what's the difference between View Share and View Composer

heizenberg left a reply on Laravel Modal

It's working fine now. Here is my routes.php

Route::group(['prefix' => 'dashboard', 'namespace' => 'Dashboard'], function()
{
    Route::get('/', [
        'as'    => 'dashboard.home',
        'uses'  => 'PagesController@home'
    ]);

    // Dashboard products route resource...
    Route::resource('products', 'ProductsController');
});

heizenberg left a reply on Laravel Modal

@bimalshah72 Thank you for your good answer and explanation. Maybe I can set my data-* to set the route foreach product like this and remove the data-product_id="{{ $product->id }}" because I dont need it anymore

<button type="button" class="btn btn-xs btn-default btn-flat" data-toggle="modal" data-target="#confirmProductDeletion"
              data-product_name="{{ $product->name }}"
              data-product_destroy_route="{{ route('dashboard.products.destroy', $product->id) }}">
              <i class="fa fa-trash"></i>
</button>

heizenberg left a reply on Laravel Modal

Hello thank you for your answer.

The $("#confirmDelete #pName").val( productName ); is not working so I change .val to .text

How can I use my named route here? $("#delForm").attr('action', 'put your action here with productId');//e.g. 'domainname/products/' + productId

02 Aug
4 years ago

heizenberg started a new conversation Laravel Modal

Anyone can help me in my problem on how to solve bootstrap modal to receive Laravel data.

https://laracasts.com/discuss/channels/laravel/figure-out-what-product-to-delete

heizenberg left a reply on Figure Out What Product To Delete

EDITED: Move the modal outside of foreach loop. But's its not picking what product to delete.

heizenberg left a reply on Figure Out What Product To Delete

No that I think about it, I put my modal inside a foreach loop. When the products is 100 the html modal is 100 too. Hmmm

heizenberg started a new conversation Figure Out What Product To Delete

How to get what product to delete on the bootstrap modal

@foreach($products as $product)
                        <tr>
                            <td>{{ $product->name }}</td>
                            <td>{{ $product->description }}</td>
                            <td>{{ $product->updated_at->diffForHumans() }}</td>
                            <td>{{ $product->created_at->diffForHumans() }}</td>
                            <td>
                                <div class="btn-group">
                                    <a href="{{ route('dashboard.products.show', [$product->slug]) }}" class="btn btn-xs btn-default btn-flat"><i class="fa fa-eye"></i></a>
                                    <a href="{{ route('dashboard.products.edit', [$product->slug]) }}" class="btn btn-xs btn-default btn-flat"><i class="fa fa-edit"></i></a>
                                    <button type="button" class="btn btn-xs btn-default btn-flat" data-toggle="modal" data-target="#confirmDelete"><i class="fa fa-trash"></i></button>
                                </div>
                            </td>
                        </tr>
                    @endforeach

<div class="modal fade" id="confirmDelete" tabindex="-1" role="dialog" aria-labelledby="confirmDelete">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                        <h4 class="modal-title">Confirm Product Deletion</h4>
                                    </div>
                                    <div class="modal-body">
                                        <p>Are you sure you want to delete {{ $product->name }}?</p>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                        {!! Form::open(['method' => 'DELETE', 'route' => ['dashboard.products.destroy', $product->id]]) !!}
                                        <button type="submit" class="btn btn-primary">Delete</button>
                                        {!! Form::close() !!}
                                    </div>
                                </div>
                            </div>
                        </div>

My controller's destroy method

public function destroy($id)
    {
        $product = $this->product->findOrFail($id);

        $product->destroy($id);

        return redirect()->route('dashboard.products.index')->with('alert-danger', 'Product successfully deleted.');
    }
29 Jul
4 years ago

heizenberg started a new conversation Administrator Redirect

Hello I'am trying to build an app with user and administrator. I'm wondering where to check if the user trying to login is an administrator or just a regular user. Administrator will be redirected in the dashboard and the user to it's profile or when caught in the middleware, redirect intended. My solution here is to set the $redirectPath = '/dashboard' in the AuthController and make an admin middleware and let that middleware check if the authenticated user is an administrator.

<?php

namespace App\Http\Middleware;

use ...

class MustBeAdministrator
{
    ...
    ...
    
    public function handle($request, Closure $next)
    {
        if ($this->auth->check() && $this->user->admin)
        {
            return $next($request);
        }

        return redirect()->route('home');
    }
}

Suggestions? :D

28 Jul
4 years ago

heizenberg started a new conversation Mail::queue Trying To Get Property Of Non-object

<?php

class ...
{
    public function postRegister(Request $request)
    {
        $validator = $this->validator($request->all());

        if ($validator->fails()) {
            $this->throwValidationException(
                $request, $validator
            );
        }

        $user = $this->create($request->all());

        Mail::queue('auth.emails.confirm', compact('user'), function($message) use ($user)
        {
            $message->to($user->email)
                    ->from(env('MAIL_FROM'), env('MAIL_NAME'))
                    ->subject('ACCOUNT ACTIVATION');
        });

        return redirect()->route('home')->with('alert-success',
        'Please check your email to activate your account.');
    }
}

In my confirm.blade.php

{{ route('register.confirm', [ $user->token ]) }}

The token was set in the User status boot method.

The code is working when using Mail::send(); My mail driver is mailgun

heizenberg started a new conversation '

'