moses

moses

Member Since 3 Years Ago

Experience Points 6,620
Experience Level 2

3,380 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 0
Lessons
Completed
Best Reply Awards 0
Best Reply
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.

13 Jun
4 days ago

moses left a reply on How Can I Make Default Page Number To Every Sheet On Maatwebsite?(laravel-excel)

@bobbybouwmann So you mean there is no function in the library that can help me? My page is dynamic depending on the data in the database. So it seems to be difficult for me to make that function

11 Jun
6 days ago

moses started a new conversation How Do I Make Automatic Height Row Based On Content In The Maatwebsite Version 3 Laravel Excel?

I had search reference and the reference say to try like this :

<?php   
...
class ReportExport implements ShouldAutoSize, FromView, WithColumnFormatting, WithEvents
{
    ...
    public function registerEvents(): array
    {
        return [
            AfterSheet::class    => function(AfterSheet $event) {
                ...
                $event->sheet->getDelegate()->getRowDimension(37)->setRowHeight(-1);
                $event->sheet->getDelegate()->getStyle('R37:Z37')->getAlignment()->setWrapText(true);
            },
        ];
    }
}

I try like that, but the result like this :

enter image description here

Should the height of row automatic added based content/text. But it does not added

How can I solve this problem?

Update :

Seems this script : $event->sheet->getDelegate()->getRowDimension(37)->setRowHeight(-1); is not working in the table

I tried the script outside the table, it worked. So the script only work outside table tag

My table like this :

<table>
    ....
    @php ($group = 'A')
    @php ($number = 0)
    @foreach($values as $item)
    @if($number==0 || $group!=$item['group'])
    <tr>
        <td colspan="9">Kelompok {{$item['group']}}</td>
        <td colspan="2"></td>
        <td colspan="3"></td>
        <td colspan="3"></td>
        <td colspan="9"></td>
        <td colspan="2"></td>
        <td colspan="3"></td>
        <td colspan="3"></td>
        <td colspan="9"></td>
    </tr>
    @php ($number = 0)
    @endif
    <tr>
        <td style="text-align:center;" colspan="2">{{++$number}}</td>
        <td colspan="7">{{$item['lesson_name']}}</td>
        <td style="text-align:center;" colspan="2">{{$item['kb_pengetahuan']}}</td>
        <td style="text-align:center;" colspan="3">{{$item['nilai_pengetahuan']}}</td>
        <td style="text-align:center;" colspan="3">{{$item['predikat_pengetahuan']}}</td>
        <td colspan="9">{{$item['deskripsi_pengetahuan']}}</td>
        <td style="text-align:center;" colspan="2">{{$item['kb_keterampilan']}}</td>
        <td style="text-align:center;" colspan="3">{{$item['nilai_keterampilan']}}</td>
        <td style="text-align:center;" colspan="3">{{$item['predikat_keterampilan']}}</td>
        <td colspan="9">{{$item['deskripsi_keterampilan']}}</td>
    </tr>
    @php ($group = $item['group'])
    @endforeach
</table>

Please help me. I need support for PhpSpreadsheet functionality

moses started a new conversation How Can I Make Default Page Number To Every Sheet On Maatwebsite?(laravel-excel)

I use laravel 5.6, php 7.1 and maatwebsite 3.1

My script to display page number like this :

$event->sheet->getHeaderFooter()->setOddFooter('&R&P');

It works. But my problem is I have 3 sheet. On the every sheet display page number start of 1

I want in the sheet 1, it display page number 1-3. In the sheet 2, it will display page number 4-6. And the sheet 3, it display page number 7-9

I want like that. I had searching reference, but I don't find it

Please help me to solve this problem. I need support for PhpSpreadsheet functionality

23 Feb
3 months ago

moses left a reply on Can I Make CRM Like Salesforce Using Laravel And Adminlte?

Okay no problem. Can you share your id and password. So I can remote it

moses left a reply on Can I Make CRM Like Salesforce Using Laravel And Adminlte?

Can I see that? Maybe an online demo

moses started a new conversation Can I Make CRM Like Salesforce Using Laravel And Adminlte?

I want to make CRM system with Lead Conversion and Inventory Forecast. It looks like simply version of SalesForce(https://www.salesforce.com/ap/?ir=1) but using laravel and adminLTE bootstrap.

Functional Requirements, here are the additional key modules that I need:

  1. Dashboard
  2. Leads conversion
  3. Opportunity
  4. Delivery
  5. Inventory forecast and planning
  6. Inventory forecast & planning review
  7. Generate PO

I want to make it like that. Before I made this project, I want to ask your opinion as a developer Laravel, can I make it like that?

I have searched for references on Google and no developer has created a project like this. I just want to make sure I can make CRM like Salesforce using Laravel and Bootstrap

Thanks

16 Sep
9 months ago

moses started a new conversation Why `having` Only Worked On Fields That Are `group By` On Laravel Eloquent?

My script laravel eloquent like this :

$query = $this->item->select('a.*','b.attribute_code')
    ->from('items as a')
    ->join('attr_maps as b','b.number','=','a.number')
    ->groupBy('a.number');

foreach($param as $key => $value) {
    $query = $query->having($key, '=', $value);
}

$query = $query->paginate(10);

If $param is array('number'=>'1234'), it works. No error

If $param is array('description'=>'test'), there exist error : Unknown column 'description' in 'having clause'

I tried all fields in the table items. Only the number field works. Apparently because the number field is group by

How can I solve this problem?

09 Sep
9 months ago

moses left a reply on Why POST Request From POSTMAN Returns Empty?

@qiutuleng Okay thanks. I works. I want to ask again. How can I convert it to array?

moses started a new conversation Why POST Request From POSTMAN Returns Empty?

My header in the postman like this :

enter image description here

My body like this :

enter image description here

In the routes laravel lumen, I check like this :

$router->group(['middleware' => 'auth'], function ($router) {
    ...
    $router->post('/sales-order', function (\Illuminate\Http\Request $request)
    {
        echo '<pre>';print_r($request->all());echo '</pre>';die();
    });
});

The result in the postman return empty array like this :

enter image description here

How can I solve the error?

03 Sep
9 months ago

moses started a new conversation How Can I Solve "Fatal Error: Out Of Memory..." When I Run Command Schedule Laravel?

My command like this :

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\ItemDetail;
class ImportItemDetail extends Command
{
    protected $signature = 'sync:item-detail';
    protected $description = 'sync item detail';
    public function __construct()
    {
        parent::__construct();
        ini_set('max_execution_time', 0);
        ini_set('memory_limit', '-1');
    }
    public function handle()
    {
        $path = storage_path('json/ItemDetail.json');
        $json = json_decode(file_get_contents($path), true);
        foreach ($json['value'] as $value) {
            ItemDetail::updateOrCreate(
                [ 'entry_number' => $value['Entry_Number'] ],
                [ 
                    'item_number' => $value['Item_Number'],
                    'description' => $value['Description'],
                    ....
                ]
            );
        }
    }
}

If I run the commmand, there exist error like this :

Fatal error: Out of memory (allocated 255852544) (tried to allocate 8192 bytes)

Whereas I had set ini_set('memory_limit', '-1'); in construct

How can I solve the error?

Note :

My record in the json file contains hundreds of thousands of data. So it takes a long time to check the fiel

02 Sep
9 months ago

moses started a new conversation How Can I Call Command Schedule Via Url On The Laravel?

I using laravel 5.6

I set my schedule in the kernel.php like this :

<?php
namespace App\Console;
use App\Console\Commands\ImportLocation;
use App\Console\Commands\ImportItem;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
    protected $commands = [
        ImportLocation::class,
        ImportItem::class,
    ];
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('inspire')->dailyAt('23:00');

    }
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');
        require base_path('routes/console.php');
    }
}

So there are two command

I will show one of my commands like this :

namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Location;
class ImportLocation extends Command
{
    protected $signature = 'import:location';
    protected $description = 'import data';
    public function __construct()
    {
        parent::__construct();
    }
    public function handle()
    {
        ...
    }
}

I want to run the command via url. So it not run in the command promp

I try like this :

I add this script : Route::get('artisan/{command}/{param}', '[email protected]'); in the routes and I make a controller like this :

namespace App\Http\Controllers;
class CommandController extends Controller
{
    public function show($command, $param)
    {
        $artisan = \Artisan::call($command.":".$param);
        $output = \Artisan::output();
        return $output;
    }
}

And I call from url like this : http://myapp-local.test/artisan/import/location

It works. But it just run one command

I want to run all command in the kernel. So run import location and import item

How can I do it?

24 Aug
9 months ago

moses left a reply on How To Set Maximum Value Of Float In The Migration Laravel?

@Cronix Thanks. I will change it to $table->decimal('amount', 12, 2);

moses left a reply on How To Set Maximum Value Of Float In The Migration Laravel?

@pardeepkumar I had solve it. Like this : $table->float('amount', 12, 2);

moses started a new conversation How To Set Maximum Value Of Float In The Migration Laravel?

I want the maximum value entered into the field amount is 900000000

In the migration I set this :

$table->float('amount', 10, 2);

If I input data 900000000 in the mysql, there exist error :

Out of range value for column 'amount'

I give some example from my data amount :

900000000

800100200,2

1000300,32

10100000,44

etc

How an I solve this problem?

21 Aug
9 months ago

moses started a new conversation How Can I Install Git Extension In Mac OS?

I use Mac OS High Sierra version 10.13.6

I want to instal git extension

I read here : https://git-extensions-documentation.readthedocs.io/en/latest/getting_started.html#installation-macos-2-5x-only

If I run : mono GitExtensions.exe in the terminal there exist error like this :

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Process 767 detached
(lldb) quit
Abort trap: 6

How can I solve the error?

19 Aug
9 months ago

moses started a new conversation How Can I Pass Parameter Using Dynamic Breadcrums Laravel?

My breadcrumbs view like this :

Home / Dashboard / Summary / Summary Detail

If link summary detail is active, the url link like this :

http://my-app.test/admin/summary-detail?item_number=123&vendor_code=V123&from_date=2018-01-01&to_date=2018-08-01

If I click link summary, the url like this :

http://my-app.test/admin/summary

I want if I click link summary, it will get all parameter from summary detail. So I want the url like this :

http://my-app.test/admin/summary?item_number=123&vendor_code=V123&from_date=2018-01-01&to_date=2018-08-01

How can I do it?

Note

I use dynamic breadcrumbs

documentation : https://github.com/davejamesmiller/laravel-breadcrumbs

In my \routes\breadcrumbs\summary.php like this :

<?php
Breadcrumbs::for('admin.summary.index', function ($trail) {
    $trail->parent('admin.dashboard');
    $trail->push(__('Summary'), route('admin.summary.index'));
});
Breadcrumbs::for('admin.summary-detail.index', function ($trail) {
    $trail->parent('admin.summary.index');
    $trail->push(__('Summary Detail'), route('admin.summary-detail.index'));
});

I using {!! Breadcrumbs::render() !!} in view blade to get it

My routes like this :

Route::resource('summary', 'SummaryController');
Route::resource('summary-detail', 'SummaryDetailController');
17 Aug
10 months ago

moses left a reply on How Can I Display Dinamyc Key Of Array In The Laravel Blade?

@burlresearch There exist error htmlspecialchars() expects parameter 1 to be string, array given Seems it's no array of array. Try to see the collection again

moses started a new conversation How Can I Display Dinamyc Key Of Array In The Laravel Blade?

My array like this :

$data = array(
    array('item_number' => 'AB-0001','total_quantity' => '1000', 'location-a' => '500', 'location-b' => '500'),
    array('item_number' => 'AB-0002','total_quantity' => '9000', 'location-a' => '5000', 'location-b' => '4000'),
    array('item_number' => 'AB-0003','total_quantity' => '6000', 'location-a' => '2000', 'location-b' => '4000'),
);

In the view blade laravel like this :

<table>
    <tr>
        <th>ITEM NUMBER</th>
        <th>TOTAL QUANTITY</th>
        <th>LOCATION-A</th>
        <th>LOCATION-B</th>
    </tr>
        @foreach($data as $value) {
        <tr>
            <td>{{ $value['item_number']; }}</td>
            <td>{{ $value['total_quantity']; }}</td>
            <td>{{ $value['location-a']; }}</td>
            <td>{{ $value['location-b']; }}</td>
        </tr>
        @endforeach
</table>

It works. But my key of array is dinamyc. The key can change

So the array can change like this :

$data = array(
    array('item_number' => 'AB-0001','total_quantity' => '500', 'location-a' => '500'),
    array('item_number' => 'AB-0002','total_quantity' => '5000', 'location-a' => '5000'),
    array('item_number' => 'AB-0003','total_quantity' => '2000', 'location-a' => '2000'),
);

Or can change like this :

$data = array(
    array('item_number' => 'AB-0001','total_quantity' => '1500', 'location-a' => '500', 'location-b' => '500', 'location-c' => '500'),
    array('item_number' => 'AB-0002','total_quantity' => '9500', 'location-a' => '5000', 'location-b' => '4000', 'location-c' => '500'),
    array('item_number' => 'AB-0003','total_quantity' => '6500', 'location-a' => '2000', 'location-b' => '4000', 'location-c' => '500'),
);

How do I set it in the laravel view blade so that it can adjust to dynamic arrays?

Update :

Actually my array $data is collection and pagination like this :

enter image description here

15 Aug
10 months ago

moses left a reply on How Can I Convert Many Statement Mysql To Laravel Eloquent?

@jlrdw It seems you don't want to give specific answers. No problem, I will try it

14 Aug
10 months ago

moses left a reply on How Can I Convert Many Statement Mysql To Laravel Eloquent?

@jlrdw Yes I have seen that. As I talked about above. I just find PREPARE and EXECUTE on the reference. But I didn't find the SET and DEALLOCATE PREPARE there

moses left a reply on How Can I Convert Many Statement Mysql To Laravel Eloquent?

@jlrdw If you use PDO, why don't you give specific answers to my case?

moses left a reply on How Can I Convert Many Statement Mysql To Laravel Eloquent?

@jlrdw Okay thanks. Now I'm looking at that. I find PREPARE and EXECUTE . But I didn't find the PREPARE and DEALLOCATE PREPARE there

moses left a reply on How Can I Convert Many Statement Mysql To Laravel Eloquent?

@jimmck If I can do that, I won't ask here

moses left a reply on How Can I Convert Many Statement Mysql To Laravel Eloquent?

@jlrdw Before I had never used it. But my problem is there are a lot of statements in my case. That made me difficult to convert it. So I hope you can answer with the script. So I can easily understand your answer

moses started a new conversation How Can I Convert Many Statement Mysql To Laravel Eloquent?

Mysql query like this :

SELECT
  GROUP_CONCAT(DISTINCT
    CONCAT(
      'ifnull(SUM(case when location_code = ''',
      location_code ,
      ''' then quantity end),0) AS `',
      location_code , '`'
    )
  ) INTO @sql
FROM
  item_details;
SET @sql = CONCAT('SELECT item_number,SUM(quantity) as "total_quantity", ', @sql, ' 
                  FROM item_details
                   GROUP BY item_number');

PREPARE stmt FROM @sql;
EXECUTE stmt;

DEALLOCATE PREPARE stmt;

I want to convert it to laravel eloquent, but i'm confused. Because there exist many statement. There exist PREPARE, EXECUTE, SET, DEALLOCATE etc. You can see query above

How can I convert it to laravel eloquent?

01 Aug
10 months ago

moses started a new conversation How Can I Solve "Relation 'a' Is Not Instance Of HasOne Or BelongsTo." In The Laravel?

My laravel eloquent like this :

$query = ItemDetail::selectRaw('a.item_number, sum(abs(a.quantity)) as "total_quantity"')
              ->from('item_detail as a')
              ->join('items as b', 'b.id', '=', 'a.item_number');

if(isset($param['vendor'])) {
    $query = $query->where('b.vendor_id', '=', $param['vendor']);
}

$query = $query->groupBy('a.item_number')
               ->paginate($paged);

return $query;

If the query executed, there exist error like this :

Relation 'a' is not instance of HasOne or BelongsTo.

How can I solve this problem?

Update

My item model like this :

class Item extends Model
{
    ...
    protected $fillable = [
        'name',
        'vendor_id'
    ];
    public function item_details() 
    {
        return $this->hasMany(ItemDetail::class, 'id', 'item_number');
    }
}

My item detail model like this :

class ItemDetail extends Model
{
    ....
    protected $fillable = [
        'item_number',
        'name',
        'posting_date'
    ];
    public function item()
    {
        return $this->belongsTo(Item::class, 'id', 'item_number');
    }
}
08 Apr
1 year ago

moses left a reply on How Can I Solve Case-sensitive Where Like Statement On Json Data In Laravel Eloquent?

@jlrdw I try this : Order::whereRaw('LOWER(information->"$.owner") like "%?%"', strtolower($receipt)) ->paginate(5);. But it's the same

moses left a reply on How Can I Solve Case-sensitive Where Like Statement On Json Data In Laravel Eloquent?

@jlrdw I need a spesific answer. Because I had try it. But it's the same

07 Apr
1 year ago

moses started a new conversation How Can I Solve Case-sensitive Where Like Statement On Json Data In Laravel Eloquent?

I use Laravel 5.6 and mysql database.

My Laravel eloquent query is like this:

Order::where('information->owner', 'like', '%'.$receipt.'%')->paginate(5);

Information field is a JSON type.

{"owner": "Chelsea"}

If $receipt is Chel, the query returns a result.

But if $receipt is chel or CHEL, the result is empty

How can I solve this problem?

14 Mar
1 year ago

moses left a reply on How Can I Validation Object String With Validation Laravel?

@jcmargentina There exist error like this : The given data was invalid. The selected data.name field is required. The selected data.gender field is required. etc. Whereas I had fill the data

moses started a new conversation How Can I Validation Object String With Validation Laravel?

I use laravel 5.6

I use https://laravel.com/docs/5.6/validation#form-request-validation to validation server side

My controller like this :

<?php
....
use App\Http\Requests\UserUpdateRequest;

class UserController extends Controller
{
    ...
    public function update(UserUpdateRequest $request)
    {
        // dd($request->all());
    }
}

Before run statement in the update method, it will call UserUpdateRequest to validation server side

The validation like this :

namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserUpdateRequest extends FormRequest
{
    ....
    public function rules()
    {
        dd($this->request->all());
        return [
            'name'          => 'required|max:50',
            'gender'        => 'required',
            'birth_date'    => 'required',
            'address'       => 'required',
            'status'        => 'required'
        ];
    }
}

The result of dd($this->request->all()); like this :

Array
(
    [selected_data] => {"name":"agis","gender":"2","birth_date":"2018-03-13","address":"london"}
)

How can I validation if the data is object array like that?

moses started a new conversation How Can I Upload File Using Vuex Store On The Vue Component?

If I using ajax in vue component like this :

<template>
    <div>
        ...
    </div>
</template>
<script>
    export default {
        methods: {
            submitForm() {
                ...
                formData.append('file', files)
                axios.post(this.baseUrl+'/member/profile/update',
                formData,
                {
                    headers: {
                        'Content-Type': 'multipart/form-data'
                    }
                }
                ).then(function(response) {
                    console.log('success')
                })
                .catch(function(error) {
                    console.log('fail')
                })
            }
        }
    }
</script>

It works. I successfully get the file

But here I want to using vuex store

My pattern of vuex store like this :

I change my vue component like this :

<template>
    <div>
        ...
    </div>
</template>
<script>
    export default {
        methods: {
            submitForm() {
                ...
                formData.append('file', files)
                this.updateProfile({formData, reload: true})
            }
        }
    }
</script>

In the component vue, it will call updateProfile method in modules user

The modules user like this :

import { set } from 'vue'
import users from '../../api/users'
import * as types from '../mutation-types'
// initial state
const state = {
    addStatus:null
}
// getters
const getters = {
    updateProfileStatus: state =>  state.addStatus,
}
// actions
const actions = {
    updateProfile ({ dispatch,commit,state },{user,reload})
    {
        users.updateProfile(user,
            response => {
                commit(types.UPDATE_PROFILE_SUCCESS)
            },
            errors => {
                commit(types.UPDATE_PROFILE_FAILURE)
            }
        )
    }
}
// mutations
const mutations = {
    [types.UPDATE_PROFILE_SUCCESS] (state){
        state.addStatus = 'success'
    },
    [types.UPDATE_PROFILE_FAILURE] (state){
        state.addStatus = 'failure'
    }
}
export default {
    state,
    getters,
    actions,
    mutations
}

From the modules user, it will call updateProfile method in api users

The api users like this :

import Vue from 'vue'
export default {

    updateProfile (user, cb, ecb = null) {
        axios.post('/member/profile/update', user)
            .then(response => cb(response))
            .catch(error => ecb(error))
    }
}

So my pattern like that. So i'm using pattern of vuex store

My problem here is I'm still confused to send file data

If I console.log(user) in the updateProfile method on modules user, the result is undefined

How can I send file data using vuex store?

08 Mar
1 year ago

moses left a reply on Why Return Is Not Working In The Img.onload On The Vue Component?

@topvillas I'm still confused to implement the promise. Please answer with the code

moses started a new conversation Why Return Is Not Working In The Img.onload On The Vue Component?

I have vue component like this :

<template>
    <section>
        ...
    </section>
</template>
<script>
    export default {
        ...
        data() {
            return {
                allowableTypes: ['jpg', 'jpeg', 'png'],
                maximumSize: 4000000
            }
        },
        methods: {
            ...
            onFileChange(e) {
                if (this.validate(e.target.files[0])) {
                    let files = e.target.files,
                        reader = new FileReader()
                    // if any values
                    if (files.length){
                        reader.onload = (e) => {
                            this.image = e.target.result
                        }
                        reader.readAsDataURL(files[0])
                    }
                }
            },
            validate(image) {
                // validation file type  
                if (!this.allowableTypes.includes(image.name.split(".").pop().toLowerCase())) {
                    return false
                }
                // validation file size
                if (image.size > this.maximumSize) {
                    return false
                }
                // validation image resolution
                let img = new Image()
                img.src = window.URL.createObjectURL(image)
                let self = this
                img.onload = function() {
                    let width = img.naturalWidth,
                        height = img.naturalHeight

                    window.URL.revokeObjectURL(img.src)

                    if(width != 850 && height != 350) {
                        return false
                    }
                }
                return true
            }
        }
    }
</script>

If user upload image, it will call onFileChange method. Before display the image, it will call method validate to validate the image

I try validate file size and file type and it works

My problem here is validate the resolution

From my code, it seems my code is true

But I try like this :

I upload image with width = 100, height = 100

From the code, should it return false

But when I run my code, it return true

Seems return is not working in the img.onload

How can I solve this problem?

03 Mar
1 year ago

moses started a new conversation How Can I Upload Image Using Storage::put On The Laravel?

My code to upload image like this :

$file = $file->move($path, $fileName);

The code works

But I want to change it using Storage::put like this reference :

https://laravel.com/docs/5.6/filesystem#storing-files

I try like this :

Storage::put($fileName, $path);

It does not works

I'm confused, where I must put $file on the code

How can I solve this problem?

24 Feb
1 year ago

moses started a new conversation How Do I Upload Files On 2 Folders At Once In One Method On The Laravel?

I use laravel 5.6

I want to upload files on 2 folders at once. So if the image uploaded successfully in the product folder, I want the image uploaded in the thumbs folder as well

I try like this :

public function uploadImage($file)   
{
    if($file) {
        $fileName = str_random(40) . '.' . $file->guessClientExtension();
    }

    $destinationPath = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'product';

    if(!File::exists($destinationPath)) {
        File::makeDirectory($destinationPath, 0755, true);
    }

    $file->move($destinationPath, $fileName);

    $destinationPathThumb = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'product' . DIRECTORY_SEPARATOR . 'thumb';

    if(!File::exists($destinationPathThumb)) {
        File::makeDirectory($destinationPathThumb, 0755, true);
    }

    $image_resize = Image::make($file->getRealPath());  
    $image_resize->resize(300, 300);
    $image_resize->save($destinationPathThumb . DIRECTORY_SEPARATOR . $fileName);
    
    return $fileName;
}

If the code run, it just success to upload in the product folder. It did not upload in the thumbs folder

There exist error like this :

message Unable to find file (/tmp/phpUSxbEJ).

exception Intervention\Image\Exception\NotReadableException

I try run this code :

public function uploadImage($file) 
{
    if($file) {
        $fileName = str_random(40) . '.' . $file->guessClientExtension();
    }
    $destinationPathThumb = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'product' . DIRECTORY_SEPARATOR . 'thumb';

    if(!File::exists($destinationPathThumb)) {
        File::makeDirectory($destinationPathThumb, 0755, true);
    }
    $image_resize = Image::make($file->getRealPath());  
    $image_resize->resize(300, 300);
    $image_resize->save($destinationPathThumb . DIRECTORY_SEPARATOR . $fileName);
    return $fileName;
}

So I remove code to upload in product folder. I try it and it works. It success upload on the thumbs folder

So I think in one process, it only upload in one folder

Is there any other way to upload on 2 folders?

21 Feb
1 year ago

moses started a new conversation How Can I Call View Blade Laravel In Vue Component?

My view blade laravel like this :

<section class="content">
    <product-list :product-data="{{json_encode($products)}}"></product-list>
</section>

In the view blade call vue component

The vue compoponent like this :

<template>
    <div class="box">
        ...
        <div class="box-body">     
            <div class="box-footer">
                <!-- call view blade -->
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        ...
    }
</script>

In the vue component, I want to call view blade laravel

The view blade like this :

{{$products->links()}}

I want to call it because the pagination only run in view blade

How can I do it?

moses started a new conversation How Can I Display Pagination Laravel On The Vue Component?

My controller like this :

public function index()
{
    $products = $this->product->list(); 
    dd($products);
    return view('admin.product.index',compact('products'));
}

The result of dd($products); like this : https://postimg.org/image/w39usbfrv/

My view blade laravel like this :

<section class="content">
    <product-list :product-data="{{json_encode($products)}}" :page="{{json_encode($products->links())}}"></product-list>
</section>

My vue component product list like this :

<template>
    <div class="box">
        ...
            <table class="table table-list">
                ...
                <tr v-for="item in products" :key="item.id">
                    <td>{{item.name}}</td>
                    <td>{{item.createdAt}}</td>
                    <td>{{item.updatedAt}}</td>
                </tr>
                ...
            </table>
            <div class="box-footer">
                ...
                    {{this.page}}
                ...
            </div>
        ...
    </div>
</template>
<script>
    export default {
        props: ['productData','page'],
        data(){
            return {
                ...
                products: this.productData.data,
            }
        },
        ...
    }
</script>

If I run the code, the result of {{this.page}} is empty

If this : {{$products->links()}} placed in view laravel it works

But if it passed on the vue component, the result is empty

How can I solve this problem?

Note :

I know how to use ajax request. But I don't use it. Here I just want to try the another way

moses left a reply on How Can I Pass Pagination Data And Array From Controller Laravel To Vue Component?

@bobbybouwmann I just want to try it. There exist error like this : "htmlspecialchars() expects parameter 1 to be string, array given (View: /home/vagrant/code/my-app/resources/views/admin/product/index.blade.php)"

moses started a new conversation How Can I Pass Pagination Data And Array From Controller Laravel To Vue Component?

My controller like this :

public function index()
{
    $products = $this->product->list(); 
    dd($products);
    return view('admin.product.index',compact('products'));
}

The result of dd($products); like this : https://postimg.org/image/w39usbfrv/

My view blade laravel like this :

<section class="content">
    <product-list :products="{{$products}}" test="test"></product-list>
</section>

My vue component product list like this :

<template>
    <div class="box">
        ...
    </div>
</template>
<script>
    export default {
        props: ['products','test'],
        mounted(){
            console.log(this.test)
            console.log(this.products)
        }
        ...
    }
</script>

If I run the code, on the console just display result ofconsole.log(this.test)

The result of console.log(this.products) is not display

Why it not display?

How can I solve this problem?

14 Feb
1 year ago

moses left a reply on How Can I Solve "Connection Could Not Be Established With Host Smtp.gmail.com"?

@sutherland I am still confused. Because when I try on my localhost, it works. This just does not work when run the send mail on the staging server