MB

MB

Member Since 9 Months Ago

Experience Points
3,220
Total
Experience

1,780 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
3,220 XP
Sep
17
2 days ago
Activity icon

Started a new Conversation Policy, How To Check If A Cookie Is Set?

I got a model policy.

How can I check if a user have a specific cookie set? The value of the cookie does not matter here.

I tried the following but nothing happens if the first one fail:

    public function update(User $user, Pug $pug)
    {

        if($user->id == $pug->user_id) {
            return true;
        }elseif(Request::hasCookie($pug->id.'-'.$pug->assist)) {
            return true;
        }else{
            return false;
        }

    }
Sep
08
1 week ago
Activity icon

Replied to Forge, Refusing To Merge Unrelated Histories

I would prefer not, but guess that's the most simple solution :)

Sep
06
1 week ago
Activity icon

Started a new Conversation Forge, Refusing To Merge Unrelated Histories

Hi,

I got this error when trying to use Deploy Now in Laravel Forge:

 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

Have tried the following on the server (digitalocean), but the problem is the same:

git pull origin master --allow-unrelated-histories

I know what caused the problem, but not sure how to fix it. I'm a solo developer and used aws c9 for this project. I have since switched to Code. I tried to Clone the repo, but Github Desktop failed because of some errors in the .c9 config folder. Manually downloaded the files, removed the .c9 folder and pushed (-f) to github.

Any suggestions how to fix this?

, Kenneth

Aug
25
3 weeks ago
Activity icon

Replied to Failed Deployment On Forge (local Changes To Be Overwritten, Github)

Okay, so do git checkout . on the server and then Deploy on Forge right after to pull latest from Github?

Update: me running npm run prod on my server is probably correct :p

Activity icon

Started a new Conversation Failed Deployment On Forge (local Changes To Be Overwritten, Github)

I have not been having that many problems deploying changes with Laravel Forge, until now. I'm kinda new to github and not sure what to do about this error (from Forge):

 * branch            master     -> FETCH_HEAD
   e977ed3..b50e16a  master     -> origin/master
error: Your local changes to the following files would be overwritten by merge:
	public/css/app.css
	public/css/style.min.css
	public/js/app.js
	public/mix-manifest.json
Please commit your changes or stash them before you merge.
Aborting

I read somewhere to do this on the server:

git checkout .

Not sure what that does and if it works or not.

Hope someone will be able to help me here :)

, Kenneth

Aug
24
3 weeks ago
Activity icon

Replied to Laravel-Excel, How To Change Column Format When Exporting To Csv?

This is the values for both

        if ($cell->getColumn() == 'A') {
            $cell->setValueExplicit($value, DataType::TYPE_STRING);

            return true;
        }

Xdebug: "Ancient Petrified Leaf"

***

        if ($cell->getColumn() == 'B') {
            $cell->setValueExplicit($value, DataType::TYPE_NUMERIC);

            return true;
        }

Xdebug: 18703

Seems correct (first is string, last integer).

Activity icon

Replied to Laravel-Excel, How To Change Column Format When Exporting To Csv?

Yes, I have Xdebug running - not a superuser though :p What part would like you to get?

I have set a breakpoint at:

    public function map($softreserve): array
    {
        return [
*            $softreserve->item_name,
            $softreserve->item_id,
            $softreserve->item_boss,
            $softreserve->character_name,
            $softreserve->character->spec->class,
        ];
    }
Activity icon

Replied to Laravel-Excel, How To Change Column Format When Exporting To Csv?

I converted back using bindValue, but the result remain the same (string wont convert to integer and integer wont convert to string).

<?php

namespace App\Exports;

use App\SoftReserve;

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithMapping;

use PhpOffice\PhpSpreadsheet\Cell\Cell;
use Maatwebsite\Excel\Concerns\ToModel;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;

class PugsExport extends DefaultValueBinder implements FromQuery, WithCustomValueBinder, WithMapping
{

    use Exportable;

    public function __construct($id)
    {
        $this->id = $id;
    }

    public function query()
    {
        return SoftReserve::query()->where('pug_id', $this->id);
    }

    /**
     * Value binding
     * https://docs.laravel-excel.com/3.1/exports/column-formatting.html#value-binders
     */
    public function bindValue(Cell $cell, $value)
    {
        if ($cell->getColumn() == 'A') {
            $cell->setValueExplicit($value, DataType::TYPE_STRING);

            return true;
        }
        if ($cell->getColumn() == 'B') {
            $cell->setValueExplicit($value, DataType::TYPE_NUMERIC);

            return true;
        }

        // else return default behavior
        return parent::bindValue($cell, $value);
    }

    /**
    * @var $softreserve
    */
    public function map($softreserve): array
    {
        return [
            (string) $softreserve->item_name,
            $softreserve->item_id,
            $softreserve->item_boss,
            $softreserve->character_name,
            $softreserve->character->spec->class,
        ];
    }

}

No errors or anything - export works fine, except the formats of the two first columns are wrong.

I did the following test, to see if the value binding works:

    public function bindValue(Cell $cell, $value)
    {
        if ($cell->getColumn() == 'A') {
            $cell->setValueExplicit($value, DataType::TYPE_NUMERIC);

            return true;
        }

        // else return default behavior
        return parent::bindValue($cell, $value);
    }

Result in the following error (which is correct):

PhpOffice\PhpSpreadsheet\Exception
Invalid numeric value for datatype Numeric
Activity icon

Replied to Laravel-Excel, How To Change Column Format When Exporting To Csv?

I have tried using value binding as well, but it will not change from string->int and the other way around. It works fine, if I want to output as currently or some of the other models. Really weird.

Have tried with both valuebinding and columnformats.

Activity icon

Replied to Laravel-Excel, How To Change Column Format When Exporting To Csv?

Hi @palak27

That's what i'm doing already (i think) :)

https://docs.laravel-excel.com/3.1/exports/column-formatting.html

    public function columnFormats(): array
    {
        return [
            'A' => NumberFormat::FORMAT_TEXT,
            'B' => NumberFormat::FORMAT_NUMBER,
            'C' => NumberFormat::FORMAT_TEXT,
            'D' => NumberFormat::FORMAT_TEXT,
            'E' => NumberFormat::FORMAT_TEXT,
        ];
    }
```
Activity icon

Replied to Laravel-Excel, How To Change Column Format When Exporting To Csv?

Thanks for your reply @sinnbeck ,

I added it to the model as well, but the result remain the name.

    protected $casts = [
        'item_id' => 'integer',
        'item_name' => 'string',
     ];
Activity icon

Started a new Conversation Laravel-Excel, How To Change Column Format When Exporting To Csv?

Hope one of you can help me with a problem :)

I'm trying to make this:

Ancient Petrified Leaf,"18703","Majordomo Executus","Bossen","Priest"

Into this:

"Ancient Petrified Leaf",18703,"Majordomo Executus","Bossen","Priest"

Table fields:

$table->string('item_name');
$table->integer('item_id');
$table->string('item_boss');
$table->string('character_name');

Relation ($softreserve->character->spec->class,):
$table->string('class');

This is my export class:

<?php

namespace App\Exports;

use App\SoftReserve;

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;

class PugsExport implements FromQuery, WithColumnFormatting, WithMapping
{

    use Exportable;

    public function __construct($id)
    {
        $this->id = $id;
    }

    public function query()
    {
        return SoftReserve::query()->where('pug_id', $this->id);
    }

    public function columnFormats(): array
    {
        return [
            'A' => NumberFormat::FORMAT_TEXT,
            'B' => NumberFormat::FORMAT_NUMBER,
            'C' => NumberFormat::FORMAT_TEXT,
            'D' => NumberFormat::FORMAT_TEXT,
            'E' => NumberFormat::FORMAT_TEXT,
        ];
    }

    /**
    * @var $softreserve
    */
    public function map($softreserve): array
    {
        return [
            $softreserve->item_name,
            $softreserve->item_id,
            $softreserve->item_boss,
            $softreserve->character_name,
            $softreserve->character->spec->class,
        ];
    }

}

Have tried to cast item_id as (int), but nothing happens.

    /**
    * @var $softreserve
    */
    public function map($softreserve): array
    {
        return [
            $softreserve->item_name,
            (int) $softreserve->item_id,
            $softreserve->item_boss,
            $softreserve->character_name,
            $softreserve->character->spec->class,
        ];
    }

Any suggestions why I do not recieve the correct column formats when I export to CSV? Seems colA is not a string (no quotes)?? Seems colB is a string and not a number/integer (without quotes).

What am I doing wrong here?

Aug
23
3 weeks ago
Activity icon

Replied to Ask User To Refresh Page If Model Has Changed

Thank you very much @snapey exactly what I was looking for :)

Aug
20
4 weeks ago
Activity icon

Replied to Ask User To Refresh Page If Model Has Changed

@snapey Livewire looks interesting indeed (just watched the laracast video). Just to be 100% sure. The data is pulled live from the database, without pageload? So if I manually insert a new record into my database, then it will instantly show up in the table/view?

Activity icon

Started a new Conversation Ask User To Refresh Page If Model Has Changed

Hi,

I need to display a message in blade, if there is changes to model, after the user loaded the page.

E.g. User1 update something in the model. User2 see a message in top of the page asking him to reload the page because it has been updated.

Is this possible? It's related to data in a table (datatables).

My problem would have been solved, if Datatables had some kind of "livedata", so it automatically update rows if someone makes changes to the models.

Now sure where to begin. Any suggestions would be much appreciated.

, Kenneth

Aug
08
1 month ago
Activity icon

Replied to Collection Forget() Method Does Not Remove Items

I ended up using shift() on the collection instead - seems to do the trick:

@php
    # Flattern multidimensional collection, so (new) collection only contain Item ID's
    # ["1","2","3","4"]
    $sr_items = $character->softreserves->pluck('item_id')->flatten();

@endphp

@for ($i = 0; $i < $maxInputs; $i++)

    @php
        # Grab first value from collection
        # This also remove the value from the collection
        $itemID = $sr_items->shift();
    @endphp

    <label for="itemInput{{$i}}">SR #{{ $i+1 }}</label>
    <select class="" id="itemInput{{$i}}" name="softreserves[]">

        <option selected></option>
        @foreach($items as $item)

            <option value="{{ $item->id }}" {{ $item->id == $itemID ? 'selected' : '' }}>{{ $item->name }}</option>

        @endforeach

    </select>

@endfor
Activity icon

Replied to Collection Forget() Method Does Not Remove Items

Thanks for the reply Snapey.

Will try to explain what i'm trying to do.

I got a collection of Item ID's. The same ID might be in the collection more than once.

Got X mount of input select fields on the page.

I would like the select boxes to pick an ID from the collection and select that in the dropdown menu. Same for the rest of them. If no ID is in the collection, then nothing will be selected in the menu.

Example:

itemIDs["5", "6","7","6"]

selectItems["","1","2","3","4","5","6","7","8"]

Select menu #1: 5
Select menu #2: 6
Select menu #3: 7
Select menu #4: 6
Select menu #5:  [blank]

Hope that makes sense :)

Activity icon

Started a new Conversation Collection Forget() Method Does Not Remove Items

Hi,

Why does this not remove the "item/id" from the collection? The foreach loop keep grabbing the value.

Code:

@php
    # Flattern multidimensional collection, so (new) collection only contain Item ID's
    $sr_itemss = $character->softreserves->pluck('item_id')->flatten();
@endphp

@for ($i = 0; $i < $maxselects; $i++)

    <label for="itemInput{{$i}}">SR #{{ $i+1 }}</label>
    <select class="" id="itemInput{{$i}}" name="softreserves[]">

        <option selected></option>
        @foreach($items as $item)

            @php

                if($sr_itemss->contains($item->id)) {

                    $selected = 'selected';

                    # Remove Item ID from collection
                    $sr_itemss->forget($item->id);

                }else{
                    $selected = '';
                }

            @endphp

            <option value="{{ $item->id }}" {{ $selected }}>{{ $item->name }}</option>

        @endforeach

    </select>

@endfor

Collection:

echo $sr_itemss; ["18703","16811"]


//The collection is also likely to have the same number multiple times.:

["15478","62457","15478"]

// in which case it should only remove one of the numbers from the collection. Not sure if forget() will remove both of them, since I never got it to work.

My idea is to remove the item from the collection after each run, but something is wrong. It keep selecting the same option for all the select inputs.

Any help would be much appreciated.

, Kenneth.

Aug
07
1 month ago
Activity icon

Replied to Getting Syntax Error Or Access Violation When Using GroupBy

Thank you very much, problem solved :) You are both correct and I will accept the first answer.

Activity icon

Started a new Conversation Getting Syntax Error Or Access Violation When Using GroupBy

Hi,

Why do I get this error when I try to use groupBy on my queries?

SQLSTATE[42000]: Syntax error or access violation: 1055 'wowpug.soft_reserves.id' isn't in GROUP BY (SQL: select * from `soft_reserves` where `pug_id` = MLDJYVME7O group by `item_name` order by `item_name` asc)

My query:

$reserved_items = SoftReserve::select('*')
    ->where('pug_id', $pug->id)
    ->orderBy('item_name', 'asc')
    ->groupBy('item_name')
    ->get();

I read that setting mysql strick=>false will fix it, but others say that is a bad idea. https://stackoverflow.com/questions/41571271/group-by-not-working-laravel

Now sure how to fix this.

Aug
05
1 month ago
Activity icon

Started a new Conversation A User Report Getting Bitcoin_miner.jar Download Prompt

I'm not sure what to do here and not sure where to post this or where to get help :/

Hope one of you smart people will use 2 minutes to read the following and post your comments. Not even sure if there is a problem or not.

Just finished a website, test page is: https://wowpug.net/pug/ZS7I7GT42Y

One visitor (from reddit) report he/she get a "bitcoin_miner.jar" file download prompt, when they visit the above url on my website.

Have been some time tying to fire out if there is a security risk of the website and can't find anything.

I use digitalocean and Forge. Random passwords for everything. The only external source it uses is: mdbootstrap, fontawesome, googleapis and wowhead.com for tooltips.

Nothing fancy or uncommon - just standard webdev stuff.

Any idea what is causing this? Or if the problem is related to the website at all? I had like 50 people try it and they dont experience this at all.

Never had a user complaint about this before, and I'm a bit scared to be honest.

I have tried to do the following "website scans".

http://www.google.com/safebrowsing/diagnostic?site=wowpug.net
Result: OK

https://sitecheck.sucuri.net/results/wowpug.net
Result: OK

https://www.siteguarding.com/
Result: OK

(not sure how accurate those scans are, but it does not hurt i guess)

I'm not sure what to do here. Just ignore him?

Aug
03
1 month ago
Activity icon

Started a new Conversation Nova: Users Not In Menu

Hi,

Users is gone from my left/main menu - and i'm not sure why and not sure how to locate the error.

If I go to the URL, then I get a 403 permission error. http://127.0.0.1:8000/nova/resources/users

Can this be related to my User Policy?

Jul
26
1 month ago
Activity icon

Replied to Policy, My Method Does Not Receive An Instance Of The Model

Thanks, that was it ! I feel so stupid right now - I should have seen that one.

Thanks for your help :)

Activity icon

Started a new Conversation Policy, My Method Does Not Receive An Instance Of The Model

Hi,

It seems my Policy method does not recieve an instance of my "Pug" model - and i'm not sure why. Hope one of you might be able to help me out :)

It's all related to the Lock method. I can do "return true" and "return false" on the policy model just fine.

This return null (on the policy method):

dd($pug->id)

This return correct User ID (on the policy method):

dd($user->id)

The Policy (I removed some of the other methods):

namespace App\Policies;

use App\Pug;
use App\User;

use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\Access\HandlesAuthorization;

class PugPolicy
{
    use HandlesAuthorization;


    /**
     * Determine whether the user can lock/unlock the model.
     * Used for (SR)
     *
     * @param  \App\User  $user
     * @param  \App\Pug  $pug
     * @return mixed
     */
    public function lock(User $user, Pug $pug)
    {
        # Authorization, logged in user must own the model
        //return $user->id == $pug->user_id;
        dd($pug->id);
    }

}

The controller (i removed some of the methods:

namespace App\Http\Controllers;

use App\HardReserve;
use App\Item;
use App\Pug;
use App\Spec;

use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

class PugController extends Controller
{

    public function __construct()
    {
        $this->authorizeResource(Pug::class, 'pug');
        $this->middleware('auth')->except(['show','index']);
    }

    /**
     * Lock or Unlock (SR)
     */
    public function lock(Request $request, Pug $pug)
    {

        $this->authorize('lock', $pug);

        $pug = Pug::find($request->id);

        # Check if we need to Lock or Unlock the model
        if($pug->locked == 1)
            $pug->locked = 0;
        else
            $pug->locked = 1;

        $pug->save();

        # Redirect
        notify()->success('Lock changed');
        return redirect()->back();
    }

}

Hope one of you can help me here :)

Activity icon

Replied to How To Redirect To Login Page Instead Of "403 This Action Is Unauthorized"?

Thanks for your help, really appreciate it :)

Activity icon

Replied to How To Redirect To Login Page Instead Of "403 This Action Is Unauthorized"?

Should I just remove the methods that are not it use by the Policy? viewAny, view, create, restore and forceDelete.

I guess the Auth middleware handle most of that now and i have policies for the rest of the methods. Correct?

Activity icon

Replied to How To Redirect To Login Page Instead Of "403 This Action Is Unauthorized"?

That was it! Works great now, thanks a lot :)

So this is what I have now and I hope I understang it correctly :)

I have the following in my controller. It uses the auth middleware on all methods/resource, except "show" and "index". This will allow visitors to view those pages, if they are authorized. The authorizeResource works like before, allow me to authorize what users are allowed. Hope I understand it correctly now :)

Controller:

    public function __construct()
    {
        $this->authorizeResource(Pug::class, 'pug');
        $this->middleware('auth')->except(['show','index']);
    }

My Policy:

<?php

namespace App\Policies;

use App\Pug;
use App\User;

use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\Access\HandlesAuthorization;

class PugPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view any models.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function viewAny(?User $user)
    {
        # ?User = allow guests
        # Allow access without any authorization
        return true;
    }

    /**
     * Determine whether the user can view the model.
     *
     * @param  \App\User  $user
     * @param  \App\Pug  $pug
     * @return mixed
     */
    public function view(?User $user, Pug $pug)
    {
        # ?User = allow guests
        # # Allow access without any authorization
        return true;
    }

    /**
     * Determine whether the user can create models.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function create(User $user)
    {
        # Allow access without any authorization
        return true;
    }

    /**
     * Determine whether the user can update the model.
     *
     * @param  \App\User  $user
     * @param  \App\Pug  $pug
     * @return mixed
     */
    public function update(User $user, Pug $pug)
    {
        # Authorization, logged in user must own the model
        return $user->id == $pug->user_id;
    }

    /**
     * Determine whether the user can delete the model.
     *
     * @param  \App\User  $user
     * @param  \App\Pug  $pug
     * @return mixed
     */
    public function delete(User $user, Pug $pug)
    {
        # Authorization, logged in user must own the model
        return $user->id == $pug->user_id;
    }

    /**
     * Determine whether the user can restore the model.
     *
     * @param  \App\User  $user
     * @param  \App\Pug  $pug
     * @return mixed
     */
    public function restore(User $user, Pug $pug)
    {
        return false;
    }

    /**
     * Determine whether the user can permanently delete the model.
     *
     * @param  \App\User  $user
     * @param  \App\Pug  $pug
     * @return mixed
     */
    public function forceDelete(User $user, Pug $pug)
    {
        return false;
    }
}

Activity icon

Replied to How To Redirect To Login Page Instead Of "403 This Action Is Unauthorized"?

Okay, i guess is related to authorization then.

Activity icon

Replied to How To Redirect To Login Page Instead Of "403 This Action Is Unauthorized"?

Hi @ma Thanks for the reply.

I'm a bit confused, you want me to add that to the Policy?

Activity icon

Started a new Conversation How To Redirect To Login Page Instead Of "403 This Action Is Unauthorized"?

Hi,

I have added a Policy to a model and one of the routes throw this error when the user is not logged in - as it should. I would however prefer to redirect them to the login page. How can i do that (using a Policy)?

Most answers tells me to use the Auth middleware on the entire resource instead. But that does not work here, because I allow guests to do some actions on the model while only the owner can do the rest.

Controller:

    public function __construct()
    {
        $this->authorizeResource(Pug::class, 'pug');
    }

My Policy (or some of it):

    public function create(User $user)
    {

        return Auth::check();

    }

I can post the entire Policy if requested :)

The following works, but it does not feel right at all. Why use the Policy in the first place then?

Policy:

    public function create(?User $user)
    {

        //return Auth::check();
        return true;

    }

Controller:

    public function __construct()
    {
        $this->authorizeResource(Pug::class, 'pug');
    }

..
    public function create()
    {

        if(!Auth::check())
            return redirect('/login');

       ...

    }

Activity icon

Replied to My Policy Always Return False

Thanks, will look into that :)

Activity icon

Replied to My Policy Always Return False

Hi Michal,

Thanks for the reply, that solved the problem :) What do you mean by having foreign key as string? I thought that was the way to do it?

My users table is pretty standard as of now:

        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });

So I should change it to this on my "Pug" model:

$table->foreignId('user_id');
Activity icon

Started a new Conversation My Policy Always Return False

Hi,

I have this simple Policy that always return false:

public function update(User $user, Pug $pug)
    {
        return $user->id === $pug->user_id;
    }

I think the problem might be related to this, but not sure how to fix it:

dd($user->id); = 841

dd($pug->user_id); = "841"

This is my table related to the "Pug" model:

...
$table->string('user_id');
...

Is it wrong to use a string here? I thought that was best practice when adding a user to a model?

Jul
25
1 month ago
Activity icon

Replied to Disable AUTO_INCREMENT On Migration

Thank you very much for the clarification. Got it working now :)

$table->unsignedBigInteger('id')->primary();
Jul
24
1 month ago
Activity icon

Started a new Conversation Disable AUTO_INCREMENT On Migration

Hi,

I'm going to use my own integers as id for my migration.

I found this in the documentation, but it still make the column auto_increment. Why is that?

<?php

class Flight extends Model
{
    /**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;
}

This is what I have in my migration:

    public function up()
    {
        Schema::create('items', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });
    }

My model:

class Item extends Model
{

    # Disable auto increment
    public $incrementing = false;

}
Jul
23
1 month ago
Activity icon

Replied to Mix.version() Does Not Make The Files

I feel so stupid. I thought new files was created. Thanks for the help - all working. Just needed to add {{ mix() to my templates }} :)

Activity icon

Replied to Mix.version() Does Not Make The Files

Anyone? Still haven't found a solution for this :(

Jul
19
2 months ago
Activity icon

Started a new Conversation Mix.version() Does Not Make The Files

Hi,

I have this code in webpack.mix.js

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .version();

mix.styles([
    'node_modules/mdbootstrap/css/mdb.min.css',
    'resources/css/mdbootstrap.css'
], 'public/css/all.css').version();

I then run "npm run dev"

This should make versioning files, but it does not. Nothing in the pubic folder. Why is that?

Jun
29
2 months ago
Activity icon

Replied to Config() Returns Null

Error fixed, too embarrassed to say what was wrong.. :(

I have previously tried to clear the cache without much success. The thing is, I did all this in my local environment, but was testing the result in production.

The cache was only cleared locally, not on the remote production server. Running this on the remote server fixed it, of cause.

Sorry.

composer dump-autoload
php artisan config:clear
php artisan config:cache
Activity icon

Replied to Config() Returns Null

I added this to services.php instead:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Third Party Services
    |--------------------------------------------------------------------------
    |
    | This file is for storing the credentials for third party services such
    | as Stripe, Mailgun, SparkPost and others. This file provides a sane
    | default location for this type of information, allowing packages
    | to have a conventional place to find your various credentials.
    |
    */
    
    'dinero' => [
        'client_id' => '',
        'client_secret' => '',
        'client_apikey' => '',
        'client_orgid' => '',
    ],
    
    'mailgun' => [....

Then running the following in my controller:

    public function index()
    {
        dd('testing...: '. config('services.dinero.client_id'));
    }

I only see this when loading the page:

"testing...: "

Seems the problem is the same.

Using Forge with DigitalOcean. Everything works fine, except this.

Activity icon

Replied to Config() Returns Null

Yes, this is the complete file (I deleted the values):

config\dinero.php

<?php

return [

    'client_id' => '',
    'client_secret' => '',
    'client_apikey' => '',
    'client_orgid' => '',

];

Do I have to include the config file somehow, for it to work?

One note though, i'm in production mode. Not sure if that is related.

APP_ENV=production
APP_KEY=...
APP_DEBUG=true
APP_URL=http://localhost
Activity icon

Replied to Config() Returns Null

Hi,

Thanks for the reply. I read somewhere that condig:cache might fix it too, so tried that as well.

Running both config:clear and config:cache makes no difference for me, output is still null.

php artisan config:clear
php artisan config:cache
Activity icon

Started a new Conversation Config() Returns Null

Hi,

I have created my first config file (config/dinero.php) and added the following:

return [

    'client_id' => '123456',
    'client_secret' => 'removed',
    'client_apikey' => 'removed',
    'client_orgid' => 'removed',

];

I thought it was possible extract this value using this in my index controller:

dd(config('dinero.client_id'));

Why does it output null?

Hope one of you might be able to help me :)

May
27
3 months ago
Activity icon

Replied to SyntaxError: Unexpected Identifier At NativeCompileCache._moduleCompile()

Seems I fixed it :)

This is what i did:

npm cache clean --force

rm -rf node_modules package-lock.json

npm install

I then got this other error:

ERROR in ./resources/sass/app.scss
Module build failed (from ./node_modules/css-loader/index.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
ValidationError: Invalid options object. Sass Loader has been initialized using an options object that does not match the API schema.

This worked:

npm uninstall --save-dev sass-loader
npm install --save-dev [email protected]

Can now run "npm run development" with no issue.

Activity icon

Started a new Conversation SyntaxError: Unexpected Identifier At NativeCompileCache._moduleCompile()

Hey you :)

Got problems running "npm run dev" after upgrading to Laravel 7. This is what I have tried:

  • Update to latest versions.
  • Deleting node_modules folder
  • Running npm install.

Nothing seems to work and i'm not sure what to try next.

Read something about the path to cross-env has changed, but not sure what that means or where to fix it.

Any help would be very appreciated.

npm -v 6.14.5

node -v v6.17.0

This is the error I receive:

ec2-user:~/environment (master) $ npm run development

> @ development /home/ec2-user/environment
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

/home/ec2-user/environment/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^

SyntaxError: Unexpected identifier
    at NativeCompileCache._moduleCompile (/home/ec2-user/environment/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
    at Module._compile (/home/ec2-user/environment/node_modules/v8-compile-cache/v8-compile-cache.js:186:36)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (/home/ec2-user/environment/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/home/ec2-user/environment/node_modules/sass/sass.dart.js:98:17)
    at Module._compile (/home/ec2-user/environment/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (/home/ec2-user/environment/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at implementation (/home/ec2-user/environment/node_modules/laravel-mix/src/components/Sass.js:55:27)
    at implementation (/home/ec2-user/environment/node_modules/laravel-mix/src/components/Preprocessor.js:130:61)
    at global.tap (/home/ec2-user/environment/node_modules/laravel-mix/src/helpers.js:10:5)
    at Sass.loaderOptions (/home/ec2-user/environment/node_modules/laravel-mix/src/components/Preprocessor.js:128:9)
    at extractPlugin (/home/ec2-user/environment/node_modules/laravel-mix/src/components/Preprocessor.js:87:39)
    at global.tap (/home/ec2-user/environment/node_modules/laravel-mix/src/helpers.js:10:5)
    at details.forEach (/home/ec2-user/environment/node_modules/laravel-mix/src/components/Preprocessor.js:27:13)
    at Array.forEach (native)
    at Sass.webpackRules (/home/ec2-user/environment/node_modules/laravel-mix/src/components/Preprocessor.js:22:22)
    at ComponentFactory.applyRules (/home/ec2-user/environment/node_modules/laravel-mix/src/components/ComponentFactory.js:155:23)
    at Mix.listen.rules (/home/ec2-user/environment/node_modules/laravel-mix/src/components/ComponentFactory.js:66:48)
    at events.(anonymous function).forEach.handler (/home/ec2-user/environment/node_modules/laravel-mix/src/Dispatcher.js:34:47)
    at Array.forEach (native)
    at Dispatcher.fire (/home/ec2-user/environment/node_modules/laravel-mix/src/Dispatcher.js:34:28)
    at Mix.dispatch (/home/ec2-user/environment/node_modules/laravel-mix/src/Mix.js:118:25)
    at WebpackConfig.buildRules (/home/ec2-user/environment/node_modules/laravel-mix/src/builder/WebpackConfig.js:90:13)
    at WebpackConfig.build (/home/ec2-user/environment/node_modules/laravel-mix/src/builder/WebpackConfig.js:23:14)
    at Object.<anonymous> (/home/ec2-user/environment/node_modules/laravel-mix/setup/webpack.config.js:29:38)
    at Module._compile (/home/ec2-user/environment/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (module.js:586:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ec2-user/.npm/_logs/2020-05-27T15_52_27_039Z-debug.log

Not sure where to find that log (i'm using AWS C9).

May
25
3 months ago
Activity icon

Started a new Conversation How To Read Replies When Using Mailgun To Send Mails?

Hi,

I have been using Mailtrap for testing and everything seems to work fine. My plan is to use Mailgun to send mails (for production), but not sure how to handle replies from my visitors. Do I need some kind of "inbox service"? Any recommendations?

Previously (many years ago) i used cPanel and created email accounts. Then I could login and read the mails using webmail.

How do you guys handle this?

May
18
4 months ago
Activity icon

Replied to Call To A Member Function Update() On Null

@wingly That worked perfectly! Thanks.

Do you know why my Observer does not run, when this update is done? It works fine when I update a model inside Nova etc. but not using the update above.

    public function updated(Motor $motor)
    {
        
        
        if($motor->isDirty(['title', 'retail_price', 'unit_id'])) {
....
Activity icon

Started a new Conversation Call To A Member Function Update() On Null

Hi,

I'm trying to update "retail_price", if the product/model exist in the table.

What am I doing wrong here? Does first() not work for this? The product may not exist in the table, then it should just skip.

        Motor::where('manufacture_pn', $pn)
            ->first()
            ->update(['retail_price' => $retail_price]);

Getting this error:

Call to a member function update() on null
May
10
4 months ago
Activity icon

Replied to Http Client, Unsupported_grant_type

Thanks, will look into that :)