newbie360

newbie360

Member Since 1 Year Ago

Experience Points 16,910
Experience
Level
Lessons Completed 8
Lessons
Completed
Best Reply Awards 19
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

15 Sep
2 months ago

newbie360 left a reply on How To Automatically Delete Database Record Using Laravel Queues?

if don't want use windows Task Sheduler

if don't want use homestead

i think the rest method is, may be ?

  1. MySQL event scheduler

  2. save the last check time to $last_check

on boot to check the $last_check then fire your delete action, but this will check on all request, and not auto to check every mins, just like closed the browser, it do nothing

you can make a bat to turn on queue:work on windows startup, but this can't help automatically check every mins

@echo off
cd X:\
php X:\path_to_project\artisan queue:work
14 Sep
2 months ago

newbie360 left a reply on How To Create Laravel Task Sheduler On WAMP Server (localhost)

in windows can use task schedule, google search windows cron

also look http://laravel.at.jeffsbox.eu/laravel-5-redis-setup-and-stuff

jump to the bottom of the page

11 Sep
3 months ago

newbie360 left a reply on AJAX: Can Not Get Data Into Controller

are you editing another controller or method ? didn't see the $id param in the method

newbie360 left a reply on POST Method, AJAX And Routes

check '_token': token

newbie360 left a reply on How To Format Date In Blade?

{{ date('m/d/Y', 1536300084) }}
09 Sep
3 months ago

newbie360 left a reply on Profile Changes Approve/reject - Keep The Current As Active

table `user`
- id

table `user_history`
- user_id
- first_name
- last_name
- approved
- created_at
- updated_at

(99, 'Hello', null, 0, created_at, updated_at)
(99, null, 'world', 1, created_at, updated_at)
07 Sep
3 months ago

newbie360 left a reply on Run .bat File With Laravel Using Controller

@cmdobueno +1 totally agreed, with some peoples may use a lot package, but i will ask 'did you reviewed all the code before use that package'

for this reason, also need to set the open_basedir in php.ini to limit the php working directory, if any package throw error can't get your_bank_login_info.txt out side the working directory, you will know how the open_basedir is so important!!

so if you are fan of use alot package, you need set the two options in php.ini

newbie360 left a reply on Run .bat File With Laravel Using Controller

WARNING, unless you know what are you doing in the bat file, all the way use absolute path instead relative path otherwise you may destroy you system get an un-expected result

in my php.ini, i always set

disable_functions = system,curl_exec,curl_multi_exec,shell_exec,exec

unless you are running on VM with any snapshot backup

newbie360 left a reply on Retrieve Image From Storage

hmmm, no idea if can't SSH, can you use Alias instead of symlink

newbie360 left a reply on How To Use After Hooks To Form Requests

sorry, what you mean ;) ?

run in controller means AFTER FromRequest ? so no need withValidator

//controller

    public function store(YourFormRequest $request)
    {
    // here already passed the YourFormRequest

    // if you mean do another validation
        $this->validate($request, [
            'here_rule' => 'required|.......',
        ]);

    }

newbie360 left a reply on How To Use After Hooks To Form Requests

check the doc ;)

PS. becareful withValidator() is Validate BEFORE the rule

newbie360 left a reply on Retrieve Image From Storage

error 404 ? check the page html source code, the image link correct ?

try type the link direct in the browser url address

if 404, because no symbolic ref to storage/app/public

newbie360 left a reply on Use KeyBy('name') On Eager-loaded Relation

if you are look for collection method, may be mapWithKeys() ?

https://laravel.com/docs/5.6/collections#method-mapwithkeys

newbie360 left a reply on Route Model Binding For 2 Routes Does Not Work As Expected

unless you know the category ONLY in any value

Route::get('{category}', 'User\CategoryController')->where('category', '(book|car|game)')->name('category');

otherwise better change the route, may be ?

Route::get('category/{category}', 'User\CategoryController')->where('category', '.+')->name('category');
Route::get('item/{item}','User\ItemController')->where('item', '.+')->name('item');

newbie360 left a reply on Retrieve Image From Storage

store the image to public disk

Storage::disk('public')->put($filename.'/sign.png', $decoded_image);

access it by

Storage::disk('public')->url($the_path_saved_in_db);

you can also use Accessor : https://laravel.com/docs/5.6/eloquent-mutators#defining-an-accessor

newbie360 left a reply on Retrieve Image From Storage

Hi, I stored the image in storage /app /signs/intervento_x/sign.png

your path means is stored in default local disk

if you want display the image, need to store the image to public disk

thats why Laravel provide a shortcut artisan command to make the symlink for you

in windows can use this is equal the artisan command

mklink /J "K:absolute_path_to_project\public\storage" "K:absolute_path_to_project\storage\app\public"

newbie360 left a reply on Redirect With Data

after store or update, you should use return redirect() instead of return view() to prevent the client reload the page in the browser (press F5), to submit the same data again

return view()->with() is passing {{ $variable }}

return redirect()->with() is passing {{ session('variable') }}

so in the blade

@if (session('variable'))
    do somthing
@endif

https://laracasts.com/discuss/channels/laravel/after-form-complete-redirect-back-in-the-same-blade-template-but-show-the-content

06 Sep
3 months ago

newbie360 left a reply on Is There A Way To Keep Old() From Flashing Until I Want It To?

if you are talking about reuse the create and edit view

<input value="{{    old('my_field',       $fromOtherSteps['my_field']  ?? ''      )    }}" >

first time load the create view show the form, will use the highlighted

old('my_field', $fromOtherSteps['my_field'] ?? '' )

input something and submit, but validation fail, so redirect back, now use

old('my_field', $fromOtherSteps['my_field'] ?? '' )

change the input and submit, now pass the validation and redirect back show view

old('my_field', $fromOtherSteps['my_field'] ?? '' )

is this clear ?

newbie360 left a reply on Dynamically Loop Relationships

mutator you mean accessor ?

accessor won't fire until you access it

newbie360 left a reply on Undefined Offset 0

i was using the same method as @lindstrom

<input type="hidden" name="enabled" value="0">
<input type="checkbox" name="enabled" value="1">

so can easy get back the old value if validation fail, and the validation rule is

'enabled' => 'required|boolean',

have fun

newbie360 left a reply on Undefined Offset 0

look again this LOL

$input['enabled' === 'on']

newbie360 left a reply on How To Upload A Folder With Files In Laravel.

as my knowledge, i don't know how to do that ;(

newbie360 left a reply on How To Display File Input Buttons Multiple Times With Image Previwe?

just make a sample, i don't know if this you looking for

sample page : http://os33.atwebpages.com/multiple_upload_image_preview.html

    <div class="container w-50">
        <img class="border border-dark rounded" data-preview="p1" src="/default_avatar.png" width="170" height="170">
        <h6 data-file-name="p1"></h6>
        <label class="btn btn-secondary" for="p1">
            <input type="file" id="p1" name="file[]" accept=".jpg" style="display:none">
            Upload
        </label>

        <br><br>

        <img class="border border-dark rounded" data-preview="p2" src="/default_avatar.png" width="170" height="170">
        <h6 data-file-name="p2"></h6>
        <label class="btn btn-secondary" for="p2">
            <input type="file" id="p2" name="file[]" accept=".jpg" style="display:none">
            Upload
        </label>
    </div>

    <script type="text/javascript">
        $(function() {

            $('input[type=file]').change(function() {
                var id = $(this).attr('id');
                var uploadFileName = this.files[0].name;
                var strLimit = 20;
    
                //
                // prevent a long string file name
                //
                if (uploadFileName.length > strLimit) {
                    var endOfFileName = uploadFileName.substr( (uploadFileName.lastIndexOf('.') -2) );
                    var startOfFileName = uploadFileName.substr(0, (strLimit - endOfFileName.length - 3));
                    uploadFileName = startOfFileName+"..."+endOfFileName;
                }
    
                //
                // show file name
                //
                $('[data-file-name="' + id + '"]').html(uploadFileName);
    
                //
                // show image preview
                //
                var reader = new FileReader();
                reader.readAsDataURL(this.files[0]);
    
                reader.onload = function(e) {
                    $('[data-preview="' + id + '"]').attr('src', e.target.result);
                };
            });

        });
    </script>

newbie360 left a reply on My Controller File Is Not Running From Blade File

can you re-format your code

at least found one problem

@foreach ($syncs as $sync)
    {{ $sync->session_date }}
@endforeach

newbie360 left a reply on How Can I Save With One Foreach Loop Object Returned From Ajax

        foreach ($devices as $index => $deviceId) {
            // when the loop start
            // $index = device_id_1
            // $deviceId = 100

            $devicesS[] = Device::create([
                'device_id' => $deviceId,
                'name' => $request->name_[$index], // `$request->name_` not is array()
                'type' => $request->type_[$index], // same as above
                'modul_1' => $request->modul_1_[$index], // same as above
            ]);
        }
05 Sep
3 months ago

newbie360 left a reply on Showing Latest Project

After that? @newbie360

only need to add that line on each Task , Credential , Wiki model

since those 3 model is the same code

public function project()
{
    return $this->belongsTo('App\Project');
}

so Project::orderBy('updated_at', 'desc')->first()

no more...action

newbie360 left a reply on Form Validation Not Work

in your view

<input type="text" class="form-control" id="role" placeholder="Enter New Role" name="txtRole">

but in the rule use 'role' , change the rule to 'txtRole'

newbie360 left a reply on Ajax Multiple Input Fields (.on Input) POST Multiple Input Fields Value

oops this helped me thankyou

$('#title, #author, #description').on('input', function() {

newbie360 left a reply on Ajax Multiple Input Fields (.on Input) POST Multiple Input Fields Value

@jlrdw aww, i means want to prevent create a new record if live-search found any records exists in db, but now i know handle single field, don't know how to handle 3 fields

newbie360 started a new conversation Ajax Multiple Input Fields (.on Input) POST Multiple Input Fields Value

i have a form in create view, when client input on title field

it will do a live-search, if found any records, the submit button will be disabled to prevent create duplicate record

i have finished the backend code and how to disable the submit button

the problem is i know how to trigger the ajax code when title changed

but now i want if ANY of (title or author or description) changed, post all 3 fields value to backend

for example,

-- in title input aaa (post the 3 fields value to backend)
title = aaa
author = 
description =


-- ok now in author input bbb (post the 3 fields value to backend)
title = aaa
author = bbb
description =
// create view
<input type="text" id="title" name="title">
<input type="text" id="author" name="author">
<input type="text" id="description" name="description">

$(function() {
    $("#title").on("input", function () {
        var title = $("#title").val();

        // prevent spamming send request to backend
        setTimeout(function() {

            if ($("input[name=title]").val() == title) { // if true, means client is finish typing

                $.ajax({
                    type:'POST',
                    url:'/live-search',
                    data:{title: title},
                    cache: false,
                    success:function(data){
                        $("#search_result").html(data.html);
                    }
                })
                
            }

        }, 2000);
    });
});

newbie360 left a reply on Update A One-to-many Relation With Possibly Additional Data Attached

if you put the code block in the db transaction, all is safe, PS you need link up the event_id for the Relationships

and also need to setup a FK on casde delete when delete a event

as my know, this very good for me, may be you can ask other peoples any Plan B there xD

newbie360 left a reply on Update A One-to-many Relation With Possibly Additional Data Attached

so by prevent the id auto_increment grow up, i will change the eventdates table like this

- event_id
- event_date
- event_starttime
- event_endtime
- event_order (if your don't want manage the order, no need this)

ok store and update also use the same logic

// event controller public function update(Request $request, $id) { $event = Event::findOrFail($id);

// here ... just in case you need update the event

$event->save();

$rows =  $request->input('event_date'); 

//
// sync the event dates
//
$event->eventdates()->delete(); // delete all exists records

$rows = array_values($rows); // skip this if don't have event_order column

foreach ($rows as $key => value)
{
    // create all new records from request
    $eventdates = new Eventdates;
    $eventdates->event_id = $event->id;
    $eventdates->event_date = \Carbon\Carbon::createFromFormat('d-m-Y', $request->event_date[$key]);
    $eventdates->event_starttime = $request->event_starttime[$key];
    $eventdates->event_endtime = $request->event_endtime[$key] ;
    $eventdates->event_order = $key + 1; // skip this if don't have event_order column
    $eventdates->save();
}

}

newbie360 left a reply on Update A One-to-many Relation With Possibly Additional Data Attached

first i will ask in the event dates table, do you have an id auto_increment column ?

newbie360 left a reply on Update A One-to-many Relation With Possibly Additional Data Attached

delete all exists event_date then create all again

newbie360 left a reply on Update A One-to-many Relation With Possibly Additional Data Attached

you problem is something like because one-to-many does not have sync() method ?

newbie360 left a reply on How Do I Normalize This Case Into Database?

because i can't guess what you trying to do ;)

any table link up to this table ?

newbie360 left a reply on How Do I Normalize This Case Into Database?

??

id, country, jan, feb, mar, apr ...

1, usa, 0, 0, 1, 1

newbie360 left a reply on Why .env File Can Be Accessible Via Domain.

you should point the server root to pathto/your_project/public

not pathto/your_project

newbie360 left a reply on Form Validation Not Work

change

        if ($validation->fails()){

           $validation->errors()->first();
        }

to

            if ($validator->fails()) {
                return redirect()->back()
                            ->withErrors(['error' => 'Role field is required'])
                            ->withInput();
            }

newbie360 left a reply on Showing Latest Project

Task model

protected $touches = ['project']; // 'project' is ref the Relationship method below
// it means when your create / update / delete a Task, it will trigger(touch) ONCE the method project(), so it will change the updated_at in model `App\Project`


 
public function project() // <- this method name ref to the $touches
{
    return $this->belongsTo('App\Project');
}
04 Sep
3 months ago

newbie360 left a reply on Ajax Change Div Content

so you can easy reuse your view

newbie360 left a reply on Ajax Change Div Content

the blade file just a view, the main step is render the view to a variable and pass to response

<nav>
    ....
</nav>

@foreach ($users as $user)
    {{ $user->id }} - {{ $user->name }} - {{ $user->email }}

    blah ..... LOL

    <table>
        blah...
    </table>

@endforeach

just like a normal view

newbie360 left a reply on Ajax Change Div Content

i think this is hard to debug and hard to read the code,

for me, i will create a view blade file, just like a normal.blade.php view, put all your code inside

<div>
// even here is 10000 lines
</div>

and put a div with id where you want show the ajax response

<div id="groupsdWidgets"></div>

in controller render the result

$result = YourModel::blah............->get();
$renderHtml = view('normal', compact('result'))->render();
return response()->json(array('success' => true, 'html' => $renderHtml));

and the ajax

    success:function(data){
        $("#groupsdWidgets").html(data.html);

    }

newbie360 left a reply on Invalid Argument Supplied For Foreach()

    protected function create( array $data)
    {
        dd($data); // show the result

newbie360 left a reply on Php How To Efficiently Loop Over Nested Array?

foreach ($items as $item)
{
    // $item['url']
}

newbie360 left a reply on Can I Zip Or Rar Images Without A Package?

i know this look ugly ;)

$zip = new ZipArchive;

if ( $zip->open('path/where_to_save/example.zip', ZipArchive::CREATE) !== TRUE)
{
    return 'Can't create zip file. ERROR:' . $zip->getStatusString();
}

$files = glob('path/where_the_files/*');

foreach ($files as $file)
{
    $zip->addFile($file, basename($file));
}

if ($zip->close() !== TRUE)
{
    return 'Can't close Zip file. ERROR:' . $zip->getStatusString();
}

// check the zip file is created ?

newbie360 left a reply on Can I Zip Or Rar Images Without A Package?

if you want learn something other than use package

you can use ZipArchive;

ofc your code may look ugly at the beginning ;) , my code also look ugly

newbie360 left a reply on Data Is Not Saving In Database

    if ($request->get('button_action') == "insert")
    {
        dd('ok');
        
        foreach ($month_year_multi_ids as $index => $values)
        {
            $company_year = new CompanyYear;
            $company_year->company_id = $company;
            $company_year->year = $year[$index];
            $company_year->month = $month[$index];
            $company_year->save();
        }

    }            

did you see ok ?

and why you loop two times of $month_year_multi_ids

combine the first and second loop, so no need use array $year[] $month[]

03 Sep
3 months ago

newbie360 left a reply on How To Model Thumbnails?

can i ask

1 video has many thumbnails ?