finchy70

finchy70

Head of Systems at EPS

Member Since 3 Years Ago

Swansea

Experience Points
19,100
Total
Experience

900 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
135
Lessons
Completed
Best Reply Awards
1
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 4
19,100 XP
Jul
30
1 week ago
Activity icon

Awarded Best Reply on Passing Values To A Component

After reading the docs again I have now declared the variables in the components class and all works.

Activity icon

Replied to Passing Values To A Component

After reading the docs again I have now declared the variables in the components class and all works.

Activity icon

Started a new Conversation Passing Values To A Component

I have a blade template

@extends('layouts.app')

@section('content')
    <div class="mb-4 bg-white shadow overflow-hidden sm:rounded-md px-4 py-4 sm:px-6 text-center">
        Jobs for week {{\Carbon\Carbon::now()->startOfWeek()->format('d-m-Y')}} to {{\Carbon\Carbon::now()->endOfWeek()->format('d-m-Y')}}
    </div>
    <div class="mb-4 grid grid-cols-7 gap-2 text-xs">
        <div>Mon: {{Carbon\Carbon::parse($start_of_week)->format('d-m-y')}}</div>
        <div>Tues: {{Carbon\Carbon::parse($start_of_week->copy()->addDays(1))->format('d-m-y')}}</div>
        <div>Wed: {{Carbon\Carbon::parse($start_of_week->copy()->addDays(2))->format('d-m-y')}}</div>
        <div>Thur: {{Carbon\Carbon::parse($start_of_week->copy()->addDays(3))->format('d-m-y')}}</div>
        <div>Fri: {{Carbon\Carbon::parse($start_of_week->copy()->addDays(4))->format('d-m-y')}}</div>
        <div>Sat: {{Carbon\Carbon::parse($start_of_week->copy()->addDays(5))->format('d-m-y')}}</div>
        <div>Sun: {{Carbon\Carbon::parse($start_of_week->copy()->addDays(6))->format('d-m-y')}}</div>
    </div>
    <hr class="mb-4">

    @foreach($entries as $entry)
        <div class="mb-2 grid grid-cols-7 gap-2">
            @if($entry->start_date <= $start_of_week && $entry->end_date >= $end_of_week)
                <x-diary-entry :entry="$entry" cols="7" />
            @endif
        </div>
    @endforeach

In the template I pass :entry="$entry cols="7". These are then shown as undefined in the component. What am I doing wrong?

Here is the component

@props([
'entry',
'cols'
])

<div>
    <li class="col-span-{{$cols}} bg-white rounded-lg shadow">
        <div class="w-full flex items-center justify-between p-6 space-x-6">
            <div class="flex-1 truncate">
                <div class="flex items-center space-x-3">
                    <h3 class="text-gray-900 text-sm leading-5 font-medium truncate">{{$entry->job_title}}</h3>
                    <span class="flex-shrink-0 inline-block px-2 py-0.5 text-teal-800 text-xs leading-4 font-medium bg-teal-100 rounded-full">Admin</span>
                </div>
                <p class="mt-1 text-gray-500 text-sm leading-5 truncate">Regional Paradigm Technician</p>
            </div>
            <img class="w-10 h-10 bg-gray-300 rounded-full flex-shrink-0" src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=facearea&amp;facepad=4&amp;w=256&amp;h=256&amp;q=60" alt="">
        </div>
        <div class="border-t border-gray-200">
            <div class="-mt-px flex">
                <div class="w-0 flex-1 flex border-r border-gray-200">
                    <a href="#" class="relative -mr-px w-0 flex-1 inline-flex items-center justify-center py-4 text-sm leading-5 text-gray-700 font-medium border border-transparent rounded-bl-lg hover:text-gray-500 focus:outline-none focus:shadow-outline-blue focus:border-blue-300 focus:z-10 transition ease-in-out duration-150">
                        <svg class="w-5 h-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor">
                            <path d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884z" />
                            <path d="M18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z" />
                        </svg>
                        <span class="ml-3">Email</span>
                    </a>
                </div>
                <div class="-ml-px w-0 flex-1 flex">
                    <a href="#" class="relative w-0 flex-1 inline-flex items-center justify-center py-4 text-sm leading-5 text-gray-700 font-medium border border-transparent rounded-br-lg hover:text-gray-500 focus:outline-none focus:shadow-outline-blue focus:border-blue-300 focus:z-10 transition ease-in-out duration-150">
                        <svg class="w-5 h-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor">
                            <path d="M2 3a1 1 0 011-1h2.153a1 1 0 01.986.836l.74 4.435a1 1 0 01-.54 1.06l-1.548.773a11.037 11.037 0 006.105 6.105l.774-1.548a1 1 0 011.059-.54l4.435.74a1 1 0 01.836.986V17a1 1 0 01-1 1h-2C7.82 18 2 12.18 2 5V3z" />
                        </svg>
                        <span class="ml-3">Call</span>
                    </a>
                </div>
            </div>
        </div>
    </li>
</div>
Jul
07
1 month ago
Activity icon

Started a new Conversation Select2 And Laravel Livewire

I have a select2 component in my form and I have surrounded the select with a wire:ignore.

<div wire:ignore>
    <select id="selected_tasks" name="selected_tasks" multiple="multiple" class="selected_tasks form-select block w-full transition duration-150 ease-in-out sm:text-sm sm:leading-5">
        @foreach($tasks as $task)
            <option value="{{$task->id}}">
                {{$task->title}}
             </option>
         @endforeach
    </select>
</div>

The problem I have is if I submit my form and it fails validation the select2 component no longer lets you add or remove items.

Does anyone know why this is happening?

Jun
29
1 month ago
Activity icon

Replied to Error When Passing Data With Function In Livewire

Fixed it by doing this instead. Probably not the best way.

@for($i=0; $i < count($existing_controls); $i++)
	<div class="text-xs">{{$existing_controls[$i]}} - <button class="text-red-500 italic" wire:click="removeControl({{$i}})">Remove</button></div>
@endfor

and this in my livewire controller

public function removeControl($index)
    {
        unset($this->existing_controls[$index]);
        $this->existing_controls = array_values($this->existing_controls);
    }
Activity icon

Started a new Conversation Error When Passing Data With Function In Livewire

@foreach($existing_controls as $control)
	<div class="text-xs">{{$control}} - <button class="text-red-500 italic" wire:click="removeControl({{$control}})">Remove</button></div>
@endforeach

I just want to send the value of $control back to the removeControl function in Livewire.

I get error

Uncaught ReferenceError: fsda (which is the value of the test string I passed) is not defined
    at eval (eval at parseOutMethodAndParams (directive.js:55), <anonymous>:1:30)
    at _default.parseOutMethodAndParams (directive.js:55)
    at _default.get (directive.js:20)
    at node_initializer.js:149
    at Component.value (index.js:421)
    at HTMLButtonElement.<anonymous> (node_initializer.js:141)

Function is

public function removeControl($control)
    {
        $pos = array_search($control, $this->existing_controls);
        unset($this->existing_controls[$pos]);
    }

Anyone see what Im doing wrong?

Jun
23
1 month ago
Activity icon

Started a new Conversation Save String To DB That Contains A Variable.

I need to save a string to my Database and then insert a client name to the string when I retrieve it.

I need to create a generic record something like this. "Ensure {{$client}} has provided you with all the required paperwork" and then insert the client after I have retrieved the record.

Sorry if I have not explained this too well but I thought this would be a simple thing until I tried to do it.

Thanks in advance Paul.

May
18
2 months ago
Activity icon

Started a new Conversation Livewire Not Reactively Updating Index

I have an overlay that allows the creation of a new project.

All works except the index is not updated when a new project is created. You have to reload the page.

The livewire index component is in the projects.index view. The create component is nested in the index and uses alpine x-show to open the overlay.

livewire.projects.index

<div x-data="{ modalOpen: false}">
    @foreach($projects as $project)
        <div class="mx-3 my-4">
            <div class="bg-gray-100 px-4 py-2 mx-6 mb border rounded-t-lg border-gray-300">
                <div class="justify-between flex -ml-4 -mt-2">
                    <div class="ml-4 mt-2">
                        <h3 class="text-lg leading-6 font-medium text-gray-800">
                            {{$project->project}}
                        </h3>
                    </div>
                    <div class="ml-4 mt-2 flex-shrink-0">
                        <span class="inline-flex rounded-md shadow-sm">
                            <button type="button" class="inline-flex items-center px-2 py-1 border border-transparent text-xs leading-5 font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:shadow-outline-indigo focus:border-indigo-700 active:bg-indigo-700">
                                View
                            </button>
                        </span>
                    </div>
                </div>
            </div>
            <div class="bg-white rounded-b-lg mx-6 border-r border-l border-b  border-gray-300 py-1 px-2">
                {{$project->description}}
            </div>
        </div>
    @endforeach

    <div x-on:close-modal.window="modalOpen = false" x-on:open-new-project-modal.window=" modalOpen = true ">
        <div x-show="modalOpen" x-transition:enter="transition ease-out duration-100" x-transition:enter-start="transform opacity-0 scale-95" x-transition:enter-end="transform opacity-100 scale-100" x-transition:leave="transition ease-in duration-75" x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-95">
            <livewire:projects.create :clients="$clients" />
        </div>
    </div>
</div>

livewire.projects.index.php

<?php

namespace App\Http\Livewire\Projects;

use App\Project;
use Livewire\Component;

class Index extends Component
{
    public $project = '';
    public $description = '';
    public $clients;
    public $projects;
    protected $listeners = ['update-project-index' => 'render'];


    public function mount($clients, $projects)
    {
        $this->clients = $clients;
        $this->projects = $projects;
    }

    public function render()
    {
        $projects = Project::orderBy('created_at', 'desc')->get();
        return view('livewire.projects.index', compact('projects'));
    }
}

livewire.create.php

<?php

namespace App\Http\Livewire\Projects;

use App\Project;
use Livewire\Component;

class Create extends Component
{
    public $project = '';
    public $description = '';
    public $clients;
    public $client_id;

    public function mount($clients)
    {
        $this->clients = $clients;
        $this->client_id = $this->clients[0]->id;
    }

    public function create()
    {
        $data = $this->validate([
            'project' => 'required|unique:projects',
            'description' => 'required'
        ]);

        $project = new Project;
        $project->project = $this->project;
        $project->user_id = auth()->user()->id;
        $project->description = $this->description;
        $project->client_id = $this->client_id;
        $project->save();

        $this->emit('update-project-index');
        $this->closeModal();

    }

    public function closeModal()
    {
        $this->description = '';
        $this->project = '';
        $this->dispatchBrowserEvent('close-modal');
    }

    public function render()
    {
        return view('livewire.projects.create');
    }
}

As you can see I have tried to trigger the update with a backend livewire event called 'update-project-index' but this does not work.

A simular setup in my clients code works with an inplace edit so I'm not sure why this doesn't work.

Any ideas?

May
13
2 months ago
Activity icon

Replied to Check For Validation Errors

        $response->assertJsonValidationErrors('file');

Yes that works too. Thanks.

Activity icon

Replied to Check For Validation Errors

Yes strange.

Activity icon

Replied to Check For Validation Errors

There is probably a more attractive way of doing this but I got it to work using

$this->assertSame($response['errors']['file'][0], 'The file must be a file of type: doc, docx, pdf.');
Activity icon

Started a new Conversation Check For Validation Errors

I have a test that checks the type of file being uploaded. It works but I also wanted to check the validation errors.

Im using PHP 7.4, phpunit 5.5.4 and Laravel 6.18.13.

/** @test */
    public function any_file_type_other_than_pdf_doc_and_docx_cant_be_uploaded()
    {
        Storage::fake('documents');
        $client = factory(Client::class)->create();
        $user = factory(User::class)->create([
            'admin' => true,
            'client_id' => null
        ]);
        $report = factory(Report::class)->create([
            'user_id' => $user->id,
            'client_id' => $client->id
        ]);
        $type = factory(DocumentType::class)->create();
        $this->actingAs($user);
        $file = UploadedFile::fake()->create('document.png', 999);
        $this->json('POST', 'documents/'.$report->id, [
            'file' => $file,
            'type' => $type->id,
        ]);

        // Assert the file was stored...
        Storage::disk('local')->assertMissing("public/documents/{$file->hashName()}");
    }

I have tried the following.

$this->json('POST', 'documents/'.$report->id, [
            'file' => $file,
            'type' => $type->id,
        ])->assertSessionHas('errors');

Missing key 'errors'

so tried

$response = $this->json('POST', 'documents/'.$report->id, [
            'file' => $file,
            'type' => $type->id,
        ]);

        $response->assertSessionHasErrors('file', null, 'The file must be a file of type: doc, docx, pdf.');

got Failed asserting that null matches expected 'The file must be a file of type: doc, docx, pdf.'. Expected :The file must be a file of type: doc, docx, pdf. Actual :null and have also tried numerous other ways with no luck.

Uploading the wrong type returns the user to the upload form and flashes Errors: The file must be a file of type: doc, docx, pdf.

Anyone know how to check for this in my test?

Apr
26
3 months ago
Activity icon

Replied to Need To Double Click Livewire Component For It To Work.

It checks if the current user has liked the reply.

public function check_likes()
    {
        return $this->morphMany(Like::class, 'liked')->where('user_id', auth()->user()->id);
    }
Activity icon

Started a new Conversation Need To Double Click Livewire Component For It To Work.

I have a blade view that contains a livewire component. This component is rested in a loop and it gets passed the reply on each loop.

@livewire('like-button', ['reply' => $reply], key($reply->id))

The component looks like this

<div>
    @if($reply->check_likes->count() == 0)
        <button wire:click="like" class="btn-xs">
            <img style="color: #27496a" height="30" width="30" src="{{asset('images/unlike.png')}}" alt="Unlike Logo by flaticon" title="Click to like!">
        </button>
    @else
        <button wire:click="unlike" class="btn-xs">
            <img style="color: #27496a" height="30" width="30" src="{{asset('images/like.png')}}" alt="Like Logo by flaticon" title="Click to like!">
        </button>
    @endif
</div>

It toggles a thumbs up , thumbs down icon depending if the reply has been liked or not.

The livewire controller looks like this.

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class LikeButton extends Component
{

    public $reply;

    public function mount($reply)
    {
        $this->reply = $reply;
    }

    public function like(){
        return $this->reply->like();
    }

    public function unlike(){
        $this->reply->likes()->where(['user_id' => auth()->user()->id])->delete();
    }

    public function render()
    {

        return view('livewire.like-button');
    }

}

all sort of works but I must click the icon twice for it to toggle.

I'm not sure why the component doesn't update on every click.

Any ideas?

Mar
31
4 months ago
Activity icon

Replied to Test Post Doesn't Hit Endpoint

I cant believe I missed that. Thanks so much.

Activity icon

Started a new Conversation Test Post Doesn't Hit Endpoint

Here is my route.

Route::post('/likes/{reply}', '[email protected]')->name('likes.store');

Here is my test

/** @test */
    public function an_authenticated_user_can_like_any_reply()
    {
        $this->signIn();

        $reply = create(Reply::class);

        $this->withoutExceptionHandling()->post('likes/'.$reply->id);

        $this->assertCount(1, $reply->likes);
    }

Here is my controller method

public function store(Reply $reply)
    {
        dd("hit");
        return DB::table('likes')->insert([
            'user_id' => auth()->user()->id,
            'liked_id' => $reply->id,
            'liked_type' => get_class($reply)
        ]);

    }

When I run my test I get the following error. ReflectionException : Class App\Http\Controllers\Reply does not exist

As I understand ReflectionExceptions are usually caused by errors in the routes file.

I have checked my route and all seams good.

I also tried posting with exception handling on and I get a fail assertion error. Either way the controller method never gets hit as I have a dd("hit"); which is never triggered.

I am on Laravel 7. Does anyone know what I am doing wrong?

Mar
04
5 months ago
Activity icon

Started a new Conversation TinyMCE Will Not Work In My Alpine.js Generated Overlay Modal.

I have a view with two TinyMCE textareas. One is in the main view and the other is part of an overlay that is shown by alpine.js on a button click.

The one in the main view is working fine. The one in the overlay does not work and just shows a standard textarea.

@section('content')

    <div class="justify-center mx-8 my-5 border-2 border-indigo-300 rounded-lg p-4">
        <h1 class="text-2xl text-center">View Post - Category <span class="capitalize">{{$post->category->name}}</span></h1>
        <div class="text-indigo-200 m-4 p-2 text-sm md:text-xl">
            {{$post->title}}
        </div>

        <div class="text-sm md:text-lg bg-indigo-200 border-2 border-gray-400 text-indigo-800 rounded-md m-4 p-2">
            {!! $post->body !!}
        </div>
        <h5 class="text-xs md:text-sm ml-10">Replies</h5>

        @if($post->replies->count() > 0)
            @foreach($post->replies as $reply)
                <div class="bg-indigo-100 border border-gray-700 rounded-md ml-10 mr-4 my-2 p-2" x-data="{ showEdit: false }">
                    <h6 class="text-xs text-gray-900">From {{$reply->user->name}} - <span class="italic">{{$reply->created_human_friendly}}</span></h6>
                    <span class="text-sm text-gray-700">{!! $reply->reply !!}</span>
                    @if(Auth::user()->id == $reply->user_id)
                        <div class="flex justify-end mt-1">
                            <form action="{{route('comments.delete', [$reply->id])}}" method="POST">
                                @csrf
                                @method("DELETE")
                                <button class="btn-xs btn-gray"
                                        onclick="return confirm('Do you want to delete this comment?')" type="submit">
                                    Delete
                                </button>
                                <button type="button" @click="showEdit = true
                                        $nextTick(() => $refs.closeModal.focus())"
                                        class="btn-xs btn-gray ml-2">
                                    Edit
                                </button>
                            </form>
                        </div>
                        <template x-if="showEdit" >
                            <div style="background: rgba(0, 0, 0, 0.8)"
                                 x-transition:enter="transition ease-out duration-500"
                                 x-transition:enter-start="opacity-0 transform scale-90"
                                 x-transition:enter-end="opacity-100 transform scale-100"
                                 x-transition:leave="transition ease-in duration-500"
                                 x-transition:leave-start="opacity-100 transform scale-100"
                                 x-transition:leave-end="opacity-0 transform scale-90"
                                    class="fixed top-0 left-0 w-full h-full flex items-center text-black bg-white">

                                <div class="container mx-auto w-1/2 h-auto border-2 border-gray-300 bg-gray-700 rounded-lg p-4 mt-2 overflow-y-auto">
                                    <form action="{{route('comments.update', $reply->id)}}" method="POST">
                                        @csrf
                                        @method('PATCH')
                                        <textarea id="mytextarea" name="reply">{{$reply->reply}}</textarea>
                                        <div class="flex justify-end mt-4">
                                            <a href="#" x-ref="closeModal" class="btn-sm btn-indigo mr-4" @click="showEdit = false">
                                                Close
                                            </a>
                                            <button type="submit" class="btn-sm btn-indigo" @click="showEdit = false">Update</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </template>
                    @endif
                </div>
            @endforeach
        @endif
    </div>
    <div class="justify-center mx-8 my-5 border border-gray-700 rounded-lg p-4 mb-10">
        <form action="{{route('comments.store', [$post->id])}}" method="POST">
            @csrf
            <h5 class="text text-indigo-300">Add a Reply</h5>
{{--            <textarea type="text" rows="3" class="px-3 py-1 mt-4 block text-gray-800 bg-indigo-200 rounded border-2 border-gray-200 w-full" name="comment"></textarea>--}}
            <textarea id="mytinytextarea" name="reply">{{old('reply')}}</textarea>

            <div class="flex justify-end mt-4">
                <a href="{{route('posts')}}" class="inline-block bg-gray-700 mt-2 ml-4 text-sm text-gray-200 border border-indigo-300 rounded
                    px-4 py-1 font-bold hover:bg-indigo-300 hover:border-gray-200 hover:text-indigo-800">
                    Back
                </a>
                <button type="submit" class="inline-block bg-gray-700 mt-2 ml-4 text-sm text-gray-200 border border-indigo-300 rounded
                    px-4 py-1 font-bold hover:bg-indigo-300 hover:border-gray-200 hover:text-indigo-800">
                    Post Comment
                </button>
            </div>
        </form>
    </div>
@stop

Not sure why this is happening. Anyone have any ideas?

Mar
03
5 months ago
Activity icon

Replied to Can't Centre Text With Mx-auto (Tailwindcss)

<div>
    <span class="mx-auto w-1/2 text-xs font-bold italic">{{App\Paginatable::pagination_count($posts)}}</span>
</div>

doesn't work

<div>
    <span class="text-center w-3/4 text-xs font-bold italic">{{App\Paginatable::pagination_count($posts)}}</span>
</div>

doesn't work

<div class="flex">
    <span class="mx-auto text-xs font-bold italic">{{App\Paginatable::pagination_count($posts)}}</span>
</div>

works

<div>
    <div class="text-center text-xs font-bold italic">{{App\Paginatable::pagination_count($posts)}}</div>
</div>

also works. Strange?

Mar
02
5 months ago
Activity icon

Replied to Can't Centre Text With Mx-auto (Tailwindcss)

No, if I remove the flex class it aligns to the left edge.

Activity icon

Replied to Can't Centre Text With Mx-auto (Tailwindcss)

I have got it to center by putting it inside a div with class of flex.

<div class="flex">
            <span class="mx-auto text-xs font-bold italic">{{App\Paginatable::pagination_count($posts)}}</span>
        </div>
Activity icon

Started a new Conversation Can't Centre Text With Mx-auto (Tailwindcss)

I've started using Tailwind in my laravel projects and I really like it. I have got stuck.

I have two divs

<div class="mx-auto text-xs font-bold italic">{{App\Paginatable::pagination_count($posts)}}</div>
<div class="my-4">{{$posts->links()}}</div>

the mx-auto does not centre the return from the pagination count method. I have tried putting it in another div. Changing the dicv to p and h5. I cant centre the output.

Imgur

Showing x to x of x records.

Feb
26
5 months ago
Activity icon

Started a new Conversation Validating Excel Imports

I have the following code which imports from a tab named Cells on an excel spreadsheet using Laravel Excel.

namespace App\Imports;

use App\Cell;
use App\Report;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithStartRow;

class CellImport implements ToCollection, WithStartRow
{
    public function  __construct(Report $report)
    {
        $this->report_id = $report->id;
        $this->user_id = $report->user_id;
        $this->checked_on = $report->checked_on;
    }

    public function startRow(): int
    {
        return 2;
    }

    public function collection(Collection $rows)
    {
        $messages = [
            'numeric'  => 'Cells tab has error',
        ];
        Validator::make($rows->toArray(),
            [
                '*.0' => 'numeric',
                '*.1' => 'numeric',
                '*.2' => 'numeric'
            ],
        $messages)->validate();


        foreach ($rows as $row) {
            if ($row->filter()->isNotEmpty()) {
                Cell::create([
                    'report_id' => $this->report_id,
                    'cell_id' => $row[0],
                    'cell_voltage' => $row[1],
                    'cell_ohms' => $row[2]
                ]);
            }
        }
    }
}

I have made a custom validation error to let me know the tab the error occurred on but would like to inject the row and column into the custom error message to make finding the problem easier.

Any ideas on how I could do this?

Feb
13
5 months ago
Activity icon

Replied to Repack A Collection

You are a genius. Thank you.

Activity icon

Started a new Conversation Repack A Collection

I have a problem where I have a questions table that has a 'section_id' and an 'order' column.

I also have a sections table which also has an 'order' column.

I needed to get all $sections with the $questions for that section using a relationship. I tried this to get the data

$sections = Section::orderBy('order', 'asc')->with('questions')->orderBy('questions.order', 'asc')->get();

Problem is I need the sections in order, then the questions in that section also in order. Unfortunately 'orderBy('questions.order', 'asc')' does not allow to sort by a column on the related table.

I built a query to get what I needed

$questions = DB::table('sections')->join('questions', 'section_id', '=', 'sections.id')->select('sections.name as name', 'sections.order as order', 'questions.order as q_order', 'questions.question as question')->orderBy('order', 'asc')->orderBy('q_order', 'asc')->get();

Now I have what I need sort of

=> Illuminate\Support\Collection {#1058
     all: [
       {#1054
         +"name": "Electrical",
         +"order": 1,
         +"q_order": 1,
         +"question": "Fixing Wiring Inspection & Testing (Statutory)",
       },
       {#1049
         +"name": "Electrical",
         +"order": 1,
         +"q_order": 2,
         +"question": "Test?",
       },
       {#1055
         +"name": "Electrical",
         +"order": 1,
         +"q_order": 3,
         +"question": "Portable Appliance Testing PAT (Statutory)",

The problem is my blade template had a loop in loop to nicely display the $question into its $section.

            @foreach($sections as $section)
                <div class="row">
                    <div class="col-10">
                        <h4>Section - {{$section->name}}</h4>
                    </div>
                    <div class="col-2">
                        <a href="{{route('questions.section', $section->id)}}" class="btn btn-sm btn-info">Select</a>
                    </div>


                </div>
                <hr>
                <div class="row">
                    <div class="col-1">Order</div>
                    <div class="col-1">ID</div>
                    <div class="col-8">Question</div>
                </div>
                @foreach($section->questions as $question)
                    <div class="row">
                        <div class="col-1">{{$question->order}}</div>
                        <div class="col-1">{{$question->id}}</div>
                        <div class="col-8">{{$question->question}}</div>
                    </div>
                @endforeach
                <hr class="hr-red">
            @endforeach
                    

Is there a way to orderBy a column on a related table and keep the nicely structured collection that works with the loop in loop or can I pack my new query into a collection that will allow it.