MoFish

Member Since 2 Years Ago

Experience Points
3,090
Total
Experience

1,910 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
2
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.

  • Community Pillar

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

Level 1
3,090 XP
Mar
25
2 weeks ago
Activity icon

Replied to Performing An 'Update'

@tykus thank you for taking the time to reply.

Apologies, I cannot seem to get that to work for some reason.

When i tried, It did not update the table nor did it throw any form of error message.

Maybe it is my models.

Ideally it would update title and description at the same time, but I cannot get it doing one field yet,

Setting Table

name, value, site_id
subject, boom, 1
description, hello, 1

Update

public function update(Request $request, $id)
{
Setting::updateOrCreate(['site_id' => $id, 'name' => 'description'], $request->all());
}

View

<form method="POST" action="{{route('build.update', $results->id)}}" enctype="multipart/form-data">
	@csrf

	<input id="title" type="text" name="title" value="TEST1">
	<input id="description" type="text" name="description" value="TEST2">

	@method("PUT")
	<input type="submit" name="save" class="btn btn-primary" value="Save" />
</form>
class Site extends Model
{
    use HasFactory;
    public $table = "site";
    public $timestamps = false;

    public function settings()
    {
        return $this->hasMany(Setting::class);
    }

}
class Setting extends Model
{
    use HasFactory;
    public $table = "site_settings";
    public $timestamps = false;

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

    public function site()
    {
        return $this->belongsTo(Site::class);
    }

}
Activity icon

Started a new Conversation Performing An 'Update'

Hi,

I have a 'site' which can have many 'settings' (1:M)

I'm struggling to understand how I can update a settings 'value' from the site?

e.g.

public function update(Request $request, $id)
{

    // get the site with all settings
	$data = Site::with('settings')->find($id);

    /*  
    find a setting with the name 'laravel' for example
    Perform an update to set its 'value' to be 'Boom'
     */

}

Sorry, seems simple but cannot get my head around this. Thank you,

Activity icon

Replied to Performing An Update On A Many To One Relationship

Question1:

I have found a solution for this which I think works well. Its just a loop which assigns all the sites settings automatically, so i do not need to manually declare variables for each settings as proposed above.

$data = Site::with('settings')->find($id);
foreach ($data->settings as $d)
{
    $data[$d->name] = $d->value;
}

Question2:

I'm still struggling with this one. Still cannot get the suggested code working nor can i visualize the best way to update all the settings for the particular site.

$site = Site::with('settings')->find($id);
$first = $site->settings()->where('name','title')->get();
$first->value = 'somthing';
$site->push($first);
Mar
24
2 weeks ago
Activity icon

Replied to Performing An Update On A Many To One Relationship

@double-a I cannot get the update code working. I'm assuming push just adds it to the array, do i need to still perform a save() or update()?

$site = Site::with('settings')->find($id);
$first = $site->settings()->where('name','title')->get();
$first->value = 'somthing';
$site->push();
Activity icon

Started a new Conversation Performing An Update On A Many To One Relationship

Hi,

I have a db table called 'site' and a db table called 'settings'

Site

id, name
class Site extends Model
{
    use HasFactory;
    public $table = "site";
    public $timestamps = false;

    public function settings()
    {
        return $this->hasMany(Setting::class);
    }

}

Settings

id, name, value, site_id
class Setting extends Model
{
    use HasFactory;
    public $table = "site_settings";
    public $timestamps = false;

    public function site()
    {
        return $this->belongsTo(Site::class);
    }

}

Question 1 From a site listing, if i press 'edit' it displays all the settings for that particular site. I can not figure out the best way to get a 'value' for a setting by its 'name'. I therefore created a little function which passes in the 'name' and outputs the 'value' so i can use it. This currently works, however wondered if there was a better solution than having to create a function. Could I potentially get them by the 'name' as a key? Something like {{ result->settings['SettingA']->value }} or some alternative?

public function edit($id)
{
    $data = Site::find($id);
    $data->settings = Setting::where('site_id', $id)->get();
    $array = array(
        'title' => "Editing",
        'result' => $data,
    );
    return view('build.edit')->with($array);
}
<input id="settingA" type="text" name="settingA" value="{{ setting('settingA', $result->id)}}">
<input id="settingB" type="text" name="settingB" value="{{ setting('settingB', $result->id)}}">

Question2: When i press Submit on this form, i would like to perform an update for each of these settings which relate back to that particular site. I'm struggling to understand how best to achieve this, but have put my thinking in the below function in hope that someone could help guide me through the remaining steps.

public function update(Request $request, $id)
{
    $site = Setting::find($id);
    // foreach request submitted?
    // get its name
    // perform an update using the name of the request 
    $setting = Setting::where('name', $name)->where('site_id', $site_id)->first();
    $setting->update([
        'value' => $request->value,
    ]);
}
Mar
23
3 weeks ago
Activity icon

Replied to View :: Assigning A Variable Without Using @php?

@michaloravec That is exactly what i was after! I didn't know you could do an assignment in the if.

Perfect, Thanks!

Activity icon

Started a new Conversation View :: Assigning A Variable Without Using @php?

Hi,

I have an administration panel with a template editor.

I would like to improve on this slightly to give the admin the ability to retrieve particular data, and render it using blade in whatever format they wish. For example a set of hyperlinks.

The ultimate goal is to have some code to allow me to assign data to a variable, without using @php tags, but my limited understanding is that what i'm looking for may simply not be possible.

I have used liquid in the past which has a very similar approach to what I would like and i'm trying to find the best way to achieve something like the way they assign variables: https://docs.microsoft.com/en-us/powerapps/maker/portals/liquid/liquid-objects#weblinks

Liquid example

{% assign nav = weblinks[Navigation] %}
{% if nav %}
<ul>
  {% for link in nav.weblinks %}
    <li>{{ link.name | escape }}</a></li>
  {% endfor %}
</ul>
{% endif %}

In order for me to replicate this, I have tried a number of things:

A. Created a function which works well, but the top line in the @php tags look a little messy. If there is anything i could do to make this top line 'less messy' then this would be the solution i'm after.

@php $nav= collection("Navigation"); @endphp

@if($nav)
    @foreach ($nav->items as $m)
        {{ $m->name }}
    @endforeach
@endif

B. I then tried to create a blade directive as that syntax looked a little better @collection("Navigation") but could not seem to assign this to a variable in my views.

// nav ???? = @collection("Navigation");

@if($nav)
    @foreach ($nav->items as $m)
        {{ $m->name }}
    @endforeach
@endif

C: I then tried using a component, but again could not assign the data to a variable for use in my template. I understand that components have their very own templates and my 'rendering' part to go inside, but i would like to be able to render a navigation by name in any template and control how this displays.

<x-navigation name="Navigaton" />

Is there any clever method for this? or is what i'm looking for just not possible?

Is method A the best and cleanest way? that's the best of the bunch i have so far.

Thanks,

Mar
20
3 weeks ago
Mar
19
3 weeks ago
Activity icon

Started a new Conversation Do Not Render Component, Render Text

Hi,

I have a documentation page listing different component syntax e.g.

<code>
<x-alert/>
</code>

I would like to be able to display these in a code block as a reference point, however when i attempt this - the view is trying to render the actual component instead of displaying the text value (as expected).

Is there an easy way to prevent a component rendering and just display the text?

Thanks.

MoFish

Mar
17
3 weeks ago
Activity icon

Awarded Best Reply on Extending View From Db

Hi,

I ended up using components and this worked perfectly.

Example

<x-layout name="Layout">
    <x-slot name="content">
        Hello world.
    </x-slot>
</x-layout>
class Layout extends Component
{
    public $name;

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

    public function render()
    {
        // get menu with items
        $page = Template::with('page')->where('name', $this->name)->first();

        // if found
        if($page)
        {

            // put file contents into the file
            file_put_contents(resource_path('/views/layout.blade.php'), trim($page->source));

            // render the nav
            return view('layout')->with('page', $page);
            
        }
    }
    
}
Activity icon

Replied to Extending View From Db

Hi,

I ended up using components and this worked perfectly.

Example

<x-layout name="Layout">
    <x-slot name="content">
        Hello world.
    </x-slot>
</x-layout>
class Layout extends Component
{
    public $name;

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

    public function render()
    {
        // get menu with items
        $page = Template::with('page')->where('name', $this->name)->first();

        // if found
        if($page)
        {

            // put file contents into the file
            file_put_contents(resource_path('/views/layout.blade.php'), trim($page->source));

            // render the nav
            return view('layout')->with('page', $page);
            
        }
    }
    
}
Activity icon

Started a new Conversation Extending View From Db

Hi,

I have views being rendered from a database field called 'source'.

I would like to be able to use something like 'extend' to make my views a little less complex.

The problem with this approach, is that this looks for a file on disk called 'layout' which i do not have. Mine is instead in a db called 'layout' with a text field for the source.

I wondered if anyone could think of a way around me doing this?

If for example I have two rows in my database which are the name and source value. -- Layout -- Content

I'm looking for a way that content could extend 'layout' for example from content.

Would components maybe be the way to go?

Example:

Content source

@extends('layout')

@section('content')
    <h1>Hello world.</h1>
@endsection

Layout source

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
    </head>
    <body>

        <div id="mid">
            <div class="container">
                @yield('content')
            </div>
        </div>

        @yield('script')
    </body>
</html>
Mar
11
1 month ago
Activity icon

Started a new Conversation Upload Keeps Storing Tmp Filename In Db

Hi,

I'm trying to upload a file to disk and store the image filename in the database.

It is uploading to disk OK, but keeps writing xampp\tmp\php3985.tmp to the database field 'image'.

I attempted to use $request->offsetUnset('image'); to try to exclude this from the the request->all and set it myself, but that didn't appear to work.

Any help much appreciated.

Thanks,

// upload
$file = $request->file('image');
$file->move(public_path().'/images/',$file->getClientOriginalName());

// set in db
$result = new CollectionItem;
$request->offsetUnset('image');
$result->create($request->all() + [
    'user_id' => '1',
    'image' => $file->getClientOriginalName()
]);
Mar
10
1 month ago
Activity icon

Replied to Display Liquid On Page As Text

@neilstee @chaudigv

Thanks so much! didn't know about the @

Activity icon

Started a new Conversation Display Liquid On Page As Text

Hi,

I have a query which i hoped someone could help with... despite being a strange request...

In one of my views, i would like to create a 'key' of blade tags for the user.

When i am attempting to write them out, they are trying to render the actual value (as expected) and not the text version.

I have a partial workaround setting a variable in the controller but wondered if this was the best way?

Or is there some alternative method or wrapper I can use around them to prevent them rendering.

Thanks,

View ( I would like the text below to appear in my view )

{{ $m->name }} 
{{ $m->description }}
{{ $m->image }}
{{ $m->target }}

The solution i am using..

Controller

$result->code = '{{$m->name}} <br/>
{{$m->description}} <br/> 
{{$m->image}}<br/>
{{$m->target}} <br/>';

View

{{ $result->code }}
Mar
09
1 month ago
Activity icon

Replied to Getting A Value From 'with' Statement

Turns out that one the collection records did not have a template id associated which was causing it to wobble!

Thank you @michaloravec.

Activity icon

Replied to Getting A Value From 'with' Statement

Hi @michaloravec

That is exactly what i thought, but when i do {{ $r->template->name }} i get the following

ErrorException
Trying to get property 'name' of non-object (View: C:\xampp\resources\views\admin\collection\index.blade.php) 	

But you can see that when i output {{ $r->template }} it does have a name attribute.

Activity icon

Started a new Conversation Getting A Value From 'with' Statement

Hello,

I'm trying to get the 'name' of the template related to my collection, however cannot see what i have done wrong.

Controller

public function index(Request $request)
{
	$result = Collection::with('template')->orderBy('id')->get();
	$data = array(
		'title' => 'All Collections',
		'result' => $result
	);
	return view('admin.collection.index')->with($data);
}

View

@forelse ($result as $r)
	{{ $r->template }} output as per the below
	{{ $r->template->name }}
@empty
	##
@endforelse

If i do {{ $r->template }} in the view I get the following output; but i would like the name.

{"id":7,"name":"Component Gallery","user_id":1,"updated_at":"2021-03-09T15:30:57.000000Z","created_at":"2021-03-09T15:30:57.000000Z"}
Activity icon

Replied to Order/Sort Field In DB

@mostafagamal Thanks for your response.

This kind of works.. but it allows for records to have the same position e.g. two position 2 records.

Mar
08
1 month ago
Activity icon

Replied to Order/Sort Field In DB

I would like to create a function which sets the position integer, but does not use the same position number. E.g

Record 1 (position 1)

Record 2 (position 2)

Record 3 (position 3)

Record 4 (position 4)

If I press order (down) on record 3, I would like record 3 to have position 4 and record 4 to be replaced with position 3.

If I press order (up) on record 2, I would like record 2 to have position 1 and record 1 to be replaced with position 2.

I hope this makes sense.

Activity icon

Replied to Order/Sort Field In DB

@mostafagamal

This works well but I’d like to take this a step further as it allows multiple records to have the save position. How would I go about this so when I pressed the up or down arrow the position increases on the record but subsequently amends the others so I cannot have 3 positions of 3 for example.

Activity icon

Replied to Order/Sort Field In DB

@mostafagamal Thank you, as simple as that..

Activity icon

Started a new Conversation Order/Sort Field In DB

Hi,

I have a DB with a 'position' (int) column.

I'm looking to write a function to update this column based on if you press an up or down arrow.

Is there a simple solution to this using Laravel?

I'm trying to figure out the best way to do this.

Thanks,

    public function order($id, $order)
    {
        $result = CollectionItem::find($id);
        if($order=="up")
        {
            echo $result->position;
        }else{
            echo $result->position;
        }
    }
Mar
07
1 month ago
Activity icon

Replied to Route

@tykus brilliant worked a treat. Thank you.

Activity icon

Replied to Route

@tykus little bit of context.. I have a gallery for example (collection) which has an ID and I would like to create images inside of it (collection items).

My thinking here was to pass the ID of the collection into the collection item create function so they could tie up.

Thanks.

Activity icon

Started a new Conversation Route

Hi,

I'm using the default resource route to define my controller.

I would like to pass an id into the create function and have therefore tried to exclude it in the resource definition and re-create my own version, however this is not working for me, no create route appears when running php artisan route:list Assume its something fairly simple I've misunderstood.

https://laravel.com/docs/8.x/controllers#restful-partial-resource-routes

Thanks

Route::get('/admin/collectionitem/{collectionitem}', [CollectionItemController::class, 'create']);

Route::resource('/admin/collectionitem', CollectionItemController::class)->except([
    'create'
]);
Activity icon

Replied to Route Query

@tykus Dammit! I knew it would of been something silly. Thanks!

Activity icon

Started a new Conversation Route Query

Hi,

I have a few resource routes defined in my web.php file.

Route::resource('/admin/setting', SettingController::class);
Route::resource('/admin/collection', CollectionController::class);
Route::resource('/admin/collectionitem/', CollectionItemController::class);

When i run php artisan route:list, the collectionitem name does not look correct, in that it is not prefixed with collectionitem as i would have expected. This means I cannot reference {{route('collectionitem.create')}} in my view files as i intended. What have I done wrong? It seems like i followed the same process as the others.

I would like my collectionitem name to be collectionitem.index and collectionitem.create etc

I have tried clearing the route cache.

+--------+-----------+------------------------------------+-----------------------------+-------------------------------------------------------------+------------+
| Domain | Method    | URI                                | Name                        | Action                                                      | Middleware |
+--------+-----------+------------------------------------+-----------------------------+-------------------------------------------------------------+------------+
|        | POST      | admin/collection                   | collection.store            | App\Http\Controllers\Admin\[email protected]       | web        |
|        | GET|HEAD  | admin/collection                   | collection.index            | App\Http\Controllers\Admin\[email protected]       | web        |
|        | GET|HEAD  | admin/collection/create            | collection.create           | App\Http\Controllers\Admin\[email protected]      | web        |
|        | GET|HEAD  | admin/collection/{collection}      | collection.show             | App\Http\Controllers\Admin\[email protected]        | web        |
|        | PUT|PATCH | admin/collection/{collection}      | collection.update           | App\Http\Controllers\Admin\[email protected]      | web        |
|        | DELETE    | admin/collection/{collection}      | collection.destroy          | App\Http\Controllers\Admin\[email protected]     | web        |
|        | GET|HEAD  | admin/collection/{collection}/edit | collection.edit             | App\Http\Controllers\Admin\[email protected]        | web        |
|        | POST      | admin/collectionitem               | store                       | App\Http\Controllers\Admin\[email protected]   | web        |
|        | GET|HEAD  | admin/collectionitem               | index                       | App\Http\Controllers\Admin\[email protected]   | web        |
|        | GET|HEAD  | admin/collectionitem/create        | create                      | App\Http\Controllers\Admin\[email protected]  | web        |
|        | DELETE    | admin/collectionitem/{}            | destroy                     | App\Http\Controllers\Admin\[email protected] | web        |
|        | PUT|PATCH | admin/collectionitem/{}            | update                      | App\Http\Controllers\Admin\[email protected]  | web        |
|        | GET|HEAD  | admin/collectionitem/{}            | show                        | App\Http\Controllers\Admin\[email protected]    | web        |
|        | GET|HEAD  | admin/collectionitem/{}/edit       | edit                        | App\Http\Controllers\Admin\[email protected]    | web        |
|        | POST      | admin/page                         | page.store                  | App\Http\Controllers\Admin\[email protected]             | web        |
Mar
05
1 month ago
Activity icon

Started a new Conversation Mass Assignment Query

Hi, I am using the mass assignment https://laravel.com/docs/5.4/eloquent#mass-assignment in my controller which is working fine. The update way below is ideal, as i can add on a couple extra fields which are not on my form and then save them all in one swoop.

Update

$page = Page::find($id);
$page->update($request->all());
$page->user_id = auth()->user()->id;
$page->save();

How can I do the same with a create? Ideally i would like to save all the fields from the form, and have the ability to add couple extra fields which are not on the form all at the same time as per the update one above

I have tried a few things but cannot figure this out.

create

$page = new Page;
// $page->create($request->all());
// $page->uri = Str::slug($request->input('title'), '-');
// $page->user_id = auth()->user()->id;
// $page->save();

Thanks,

Activity icon

Replied to Render Blade Content From DB

@sr57 Thank you so much! This is exactly what I was looking for. Worked for both solutions.

I'll close both threads.

You are a star!

Activity icon

Replied to Render Blade Content From DB

@sr57 Apologies, I have just replied to the other thread.

  • The last thread was in regards to the rendering of a component.
  • This thread was just to render a blade file itself.

Sorry for the confusion, appreciate the solution maybe the same/similar for both.

Activity icon

Replied to Render Component From DB Field

@artcore I have tried the above and this does not appear to work.

Field content

Hello <x-render.gallery name="main" />

Controller

$page->setAttribute('bladeContent', Blade::compileString($page->content));

View

// output 1
{{ $page->bladeContent }}

// output 2
{{ $page->content }}

Output 1

Hello <?php if (isset($component)) { $__componentOriginal20e409acaf678eb2ef689891645879adf9f24867 = $component; } ?> <?php $component = $__env->getContainer()->make(App\View\Components\Render\Gallery::class, ['name' => 'main']); ?> <?php $component->withName('render.gallery'); ?> <?php if ($component->shouldRender()): ?> <?php $__env->startComponent($component->resolveView(), $component->data()); ?> <?php $component->withAttributes([]); ?> <?php if (isset($__componentOriginal20e409acaf678eb2ef689891645879adf9f24867)): ?> <?php $component = $__componentOriginal20e409acaf678eb2ef689891645879adf9f24867; ?> <?php unset($__componentOriginal20e409acaf678eb2ef689891645879adf9f24867); ?> <?php endif; ?> <?php echo $__env->renderComponent(); ?> <?php endif; ?> 

Output 2

Hello <x-render.gallery name="main" /> 
Activity icon

Started a new Conversation Render Blade Content From DB

Hi,

I'm looking to store blade html code in a DB field called 'Source' to allow this to be edited online.

an example below:

@extends('templates.layout')

@section('content')
    hello world
@endsection

@section('script')
    <script type="text/javascript">
        console.log("boom");
    </script>
@endsection

From my controller, what is the best way about rendering this? I have tried couple things without success. My thinking was to have an empty view called render which would display the source variable, but could not get this working successfully. I have tried the following in my view:

{{ $source }} or {!! $source !!} or {!! Blade::compileString(source ) !!}

And have attempted the following in my controller.

return view('templates.render')->with('source', $page->template->source);
return view('templates.render')->with('source', $page->template->source)->render();

Thanks

Mar
04
1 month ago
Activity icon

Replied to Render Component From DB Field

@neilstee thanks for the reply, i got rather excited when i seen this may be possible.

I tried this but the results were not as expected.

Its finding the gallery to render, but not rendering it per say.. see my results below.

Text component

// get page
$page = Page::select('content')->where('uri', Request::segment(1))->first();

// if page exists
if($page)
{

    // try the following
    $page->setAttribute('bladeContent', Blade::compileString($page->content));

    // render the text
    return view('components.render.text')->with('page', $page);

}

View

{{ $page->bladeContent }}

Result

Cras libero augue, lobortis vel sagittis eget, ultrices in mauris. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Aliquam pharetra neque sed lectus tempor tempor. Integer ac arcu vel erat pellentesque suscipit. Duis nisl est, finibus sed accumsan non, tristique eu est. <?php if (isset($component)) { $__componentOriginal20e409acaf678eb2ef689891645879adf9f24867 = $component; } ?> <?php $component = $__env->getContainer()->make(App\View\Components\Render\Gallery::class, ['name' => 'gallery 1']); ?> <?php $component->withName('render.gallery'); ?> <?php if ($component->shouldRender()): ?> <?php $__env->startComponent($component->resolveView(), $component->data()); ?> <?php $component->withAttributes([]); ?> <?php if (isset($__componentOriginal20e409acaf678eb2ef689891645879adf9f24867)): ?> <?php $component = $__componentOriginal20e409acaf678eb2ef689891645879adf9f24867; ?> <?php unset($__componentOriginal20e409acaf678eb2ef689891645879adf9f24867); ?> <?php endif; ?> <?php echo $__env->renderComponent(); ?> <?php endif; ?>
Mar
03
1 month ago
Activity icon

Started a new Conversation Validate Field :: Error Message Not Appearing In View

Hi,

I cannot seem to get an error message to appear underneath my capcha field.

All the fields work correctly, but doesn't seem to display a message when using the rule.

All the field outlines red as i would expect, and does not let me submit the form, so it knows its required, but no message is displayed underneath it as per the others.

Do I have to specifically assign a message? Nothing obvious is jumping out at me.

Thanks

MoFish

// validate
$this->validate($request, [
    'fullname' => 'required',
    'email' => 'required',
    'message' => 'required',
    'capcha' => [
        'required',
        Rule::in([$request->input('capchaConfirm')]),
    ],
]);
<div class="input-group">
	<input id="capcha" type="text" class="form-control {{ $errors->has('capcha') ? ' is-invalid' : '' }}" name="capcha">
</div>
@if ($errors->has('capcha'))
	<span class="invalid-feedback">
		<strong>{{ $errors->first('capcha') }}</strong>
	</span>
@endif
Activity icon

Replied to Laravel Validate Specific Word

@reached The above code actually worked :) ...

I just was not setting my variable in my example correctly.

Activity icon

Awarded Best Reply on Laravel Validate Specific Word

Got this working. I was making a silly mistake.

Activity icon

Replied to Laravel Validate Specific Word

Got this working. I was making a silly mistake.

Activity icon

Started a new Conversation Laravel Validate Specific Word

Hi,

I would like to validate that a particular word has been entered via my forms on submission. I have tried to make use of the 'word-in' https://laravel.com/docs/8.x/validation#rule-in rule, however this does not appear to be working.

I would only like the form to submit if the word 'hello' is entered on the capcha field in my form.

Could someone please let me know where I have gone wrong.

Thanks. MoFish

// word
$capcha = "hello";

// validate
$this->validate($request, [
    'fullname' => 'required',
    'capcha' => [
        'required',
        Rule::in([$capcha]),
    ],
]);
Activity icon

Started a new Conversation Render Component From DB Field

Hi all, I have a component view called 'render' which displays an image gallery and is working great!

{{ $page->content }}

<br/>

<x-render.gallery name="gallery 1" />

This page renders the page "content" from a database field and also the image gallery below it.

I wondered if it would be possible for me to put the exact same x-render code into the content field field in the DB. This would then allow me to embed particular things on a per page basis e.g. galleries.

Unfortunately it didn't quote work out and nothing appeared. I'm assuming this is because the view has already rendered at this point. See the below output.

Yay, its the homepage! <x-render.gallery name="gallery 1" />

As this is the first time playing around with components i'm not sure if this is possible

Could anyone let me know if this is achievable?

Thanks,

MoFish

Activity icon

Replied to Mail Configuration In Controller

@martinbean,

I would like to allow the end user to set this up themselves without getting involved.

My thinking was to the details stored in an encrypted table and read from there.

That would allow them to maintain/change them if required.

Do you know if it is possible at all to use a config via a controller?

Thanks,

MoFish

Activity icon

Started a new Conversation Mail Configuration In Controller

Hi all,

I have mail successfully sending from my controller using the below code, however wondered if it is possible to change the email configuration in the controller instead of loading them from the mail.php file. I would ideally like to have these configurations stored in a database and allow them to be updated via an admin interface. Something like the below would be ideal, but I am not sure how to make the Mail::send use my $config instead of the settings stored in Mail.php.

Thanks for your help.

MoFish

public function send(Request $request)
{

    // configuration
    $config = array(
        'driver'     => "xxx",
        'host'       => "xxx",
        'port'       => "xxx",
        'from'       => "xxx",
        'encryption' => "xxx",
        'username'   => "xxx",
        'password'   => "xxx",
    );

    // validation
    $this->validate($request, [
        'fullname' => 'required',
        'email' => 'required',
        'message' => 'required'
    ]);

    // data
    $data = array(
        'fullname' => $request->input('fullname'),
        'email' => $request->input('email'),
        'message' => $request->input('message')
    );

    // this is where im stuck. 
    // I don't know how to use my config declared above instead of the mail
    Mail::send('emails.contact', $data, function ($message) {
        $message->subject("Hello world");
        $message->to('[email protected]');
    });

}
Mar
02
1 month ago
Activity icon

Replied to Custom Blade Directive (Passing Parameter In)

Thank you for your response Tykus.

Ideally i would like to have have a component called 'render' which could be used in my views to display either menus or text for example:

<x-render::menu :name="$name" />
<x-render::text :name="$name" />

As i have never used these before, i'm playing around with them and have run the following artisans, however am a little confused where i should be creating the Render Component Class which will have the two functions inside. Also assuming the render will need to be placed into my boot function as per the documentation?

php artisan make:component Menu
php artisan make:component Item

Could you help clarify?

Activity icon

Started a new Conversation Custom Blade Directive (Passing Parameter In)

Hi all,

I have a custom blade directives for rendering a menu called @menu.

When i pass a static value of 'Main' it works fine.

When i pass a parameter of $name which is equal to 'Main' it does not work at all.

Does anyone have any ideas why this could be?

Thanks, Mofish

See the example code below:

Layout

@menu('Main')

AppServiceProvider

Blade::directive('menu', function ($name) {
    // alert $name;
    // $menu = Menu::where('name', "Main")->first(); 
    $menu = Menu::where('name', $name)->first(); 

    if($menu){ 
        echo "here"; 
    }
}); 
Feb
17
1 month ago
Activity icon

Replied to Relationship Query

Thank you Michal. I was trying it the wrong way around and couldn't find it in the docs.