graemenewable

graemenewable

Member Since 1 Year Ago

Experience Points
7,130
Total
Experience

2,870 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
64
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 2
7,130 XP
Jul
03
2 months ago
Activity icon

Started a new Conversation Make Npm Run Watch Only Compile Specific Assets

In my webpack.mix.js I have 2 separate Sass and JS bundles as stated below:

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

//Admin
mix.js('resources/js/admin_app.js', 'public/admin/js')
.sass('resources/sass/admin/app.scss', 'public/admin/css');

The second "admin" bundle rarely changes and does not need to be compiled.

How am I able to get npm run watch to only compile the "public" bundle. The admin bundle adds a significant amount of time so if I could only have the "public" bundle compile even if that means I could use a command like npm run watch --public, that would be ideal.

Any ideas? Thanks

Jul
01
2 months ago
Activity icon

Started a new Conversation Using An Accessor Or Mutator If The Column Has 2 Consecutive Underscores

Hi,

I have a column in my database Started_Trading__c. I'm struggling to use an accessor for this field. So far I have tried the following with no luck.

public function getStartedTrading_cAttribute()

public function getStartedTrading__cAttribute()

public function getStarted_Trading__cAttribute()

public function getStarted_Trading_cAttribute()

What would be a valid way to get an accessor working with this type of column name which has 2 consecutive underscores __c.

Unfortunately I have no control over the database column names so ideally i'd like to get this to work.

Thanks

Jun
21
3 months ago
Activity icon

Replied to Broadcasting To Guests

Thanks, that did the trick. I only knew of Private and Presense Channels.

Jun
20
3 months ago
Activity icon

Started a new Conversation Broadcasting To Guests

I'm currently making a polls/survey site as a personal project using. The basic functionality works. You can vote on a poll and using broadcasting via Pusher, the poll results update in real time.

The issue I am having is this only works if you are logged in as an authenticated user. I want to be able to display polls updating in realtime to users who are not logged in. I have tried removing any sort of auth middleware from the broadcasting routes & channels with no luck.

Is this possible and how would I approach this?

Thanks

May
25
3 months ago
Activity icon

Replied to Flash Data Not Being Written To Session

HomeController.php (where I am redirecting to)

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{

    public function index()
    {
        dd(request()->session()->all());
    }
}

At the moment I have no view as I am dd'ing to check the session.

I am setting my session from my PollController.php store function which looks like this:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PollController extends Controller
{

    public function store(Request $request)
    {
          return redirect()->route('home')->with('status', "Task was successful");
    }
}

I have reduced the PollController to return redirect only for the sake of trying to eliminate any potential conflicts.

I have also tried

return redirect()->route('home')->with(['status', "Task was successful"]);

Activity icon

Started a new Conversation Flash Data Not Being Written To Session

Im using Laravel 7.12.0 and my flash session data doesn't appear to be working at all either using

request()->session()->flash('status', 'Task was successful!');

or

return redirect()->route('home')->with('status', "Task was successful");

I am using Debugbar as well as dd'ing the page to check session data.

I also know that the web middleware is being used.

session()->put() still works so I know putting data into the session aren't entirely broken but flash data does not seem to work at all. This is a fresh installation so I am struggling to see what could be wrong?

Web.php

Auth::routes();


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

Route::group(['middleware' => ['auth']], function () {
    Route::resource('polls', 'PollController');
    Route::post('polls/vote', '[email protected]')->name('polls.vote');
});

Route::resource('api/polls', 'API\PollController');

Part of RouteServiceProvider.php

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(base_path('routes/web.php'));
    }

Web Middleware group in kernel.php

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            'throttle:60,1',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
    ];

What is in the session from my [email protected] after being redirected.

  "_token" => "pbZJgfC6XNG2eTqlcGADm68NqhjOHI16rWe4U1bt"
  "_previous" => array:1 [▼
    "url" => "http://127.0.0.1:8000"
  ]
  "_flash" => array:2 [▼
    "old" => []
    "new" => []
  ]
  "url" => []
  "login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d" => 1
]

Thanks

Apr
02
5 months ago
Activity icon

Started a new Conversation Accessing Relationship Within A Pivot Table Using BelongsToMany

Hi, I have 4 models

  • Centre
  • HealthAndSafetyDocument
  • CentreHealthAndSafetyDocument
  • Document

What I am trying to do is be able to access all the relationships within the CentreHealthAndSafetyDocument model via the Centre model (primarily Document) using a belongsToMany relationship.

Here is the relationship in the Centre model so far:

public function healthAndSafetyDocuments()
{
        return $this->belongsToMany(HealthAndSafetyDocument::class, 
        'centre_health_and_safety_documents',  
        'centre_id', 
        'health_and_safety_document_id')
        ->withPivot('document_id');
}

In my blade, if I were to do:

@foreach($centre->healthAndSafetyDocuments as $health_and_safety_document)
<tr>
    <td>{{$health_and_safety_document}}</td>
</tr>
@endforeach

This is the result I get for 1 item:

{"id":1,"title":"Fire Risk Assessment","created_at":"2020-04-02T15:41:32.000000Z","updated_at":"2020-04-02T15:41:32.000000Z","pivot":{"centre_id":2,"health_and_safety_document_id":1,"document_id":1}}

This data is only the data from the HealthAndSafetyDocument model, however I also want the data from the Document model. The best I have been able to do is add ->withPivot('document_id') to my relationship but this only gives me the document_id. I can't do $health_and_safety_document->document to retrieve the document relationship.

What can I do in this situation? Is the BelongsToMany the wrong type of relationship for what I am trying to achieve?

Below is schema for the CentreHealthAndSafetyDocument table

        Schema::create('centre_health_and_safety_documents', function (Blueprint $table) {
            $table->id();
            $table->integer('centre_id')->unsigned();
            $table->integer('health_and_safety_document_id')->unsigned();
            $table->integer('document_id')->unsigned()->nullable();
            $table->timestamp('expiry_date');
            $table->timestamps();
        });

Below is my CentreHealthAndSafetyDocument Model:

class CentreHealthAndSafetyDocument extends Model
{
    public function centre()
    {
        return $this->belongsTo(Centre::class);
    }

    public function document()
    {
        $this->hasOne(Document::class);
    }

    public function healthAndSafetyDocument()
    {
        return $this->belongsTo(HealthAndSafetyDocument::class);
    }
}

Thanks

Mar
31
5 months ago
Activity icon

Started a new Conversation Optional Properties In Blade Component

I've created a new blade component called "Card". In this component I have 2 properties, title and class. However I want class to be optional, but I get the error Unresolvable dependency resolving [Parameter #1 [ <required> $class ]] in class App\View\Components\Card if I do not state class="" when referencing the component in whatever blade I want to use the component in.

How can I make the class property optional. I would prefer to make it optional rather than having to put to do:

<x-card title="Your Account Settings" class=""></x-card>

each time I want to use the component. Optimally, I want to have:

<x-card title="Your Account Settings"></x-card>

and only state the class property when I actually need it.

For reference, here is my Card.php component file.


class Card extends Component
{
    public $title;
    public $class;

    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct($title, $class)
    {
        $this->title = $title;
        $this->class = $class;
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\View\View|string
     */
    public function render()
    {
        return view('components.card');
    }
}

and the card.blade.php


<div class="card {{$class}} shadow mb-4">
    <div class="card-header py-3">
        <h6 class="m-0 font-weight-bold text-magenta">{{$title}}</h6>
    </div>
    <div class="card-body">
        {{$slot}}
    </div>
</div>