larafam

Experience

29,420

2 Best Reply Awards

  • Member Since 1 Year Ago
  • 257 Lessons Completed
  • 0 Favorites

5th July, 2018

larafam left a reply on Weird Email 'from' Address • 2 weeks ago

4th July, 2018

larafam started a new conversation Weird Email 'from' Address • 2 weeks ago

i saw shopify doing something like "via shopify". alt text

how to do something like that in laravel application?

3rd July, 2018

larafam started a new conversation How To Fix This Vuejs Warning • 2 weeks ago

[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "addressLine2"

i have this simple address form

<template>
    <div>
        <div class="field is-grouped">
            <div class="control is-expanded">
                <label for="first_name" class="label">First name</label>
                <input type="text" class="input" id="first_name" name="first_name" v-model="firstName" :required="isRequired">
            </div>
            <div class="control is-expanded">
                <label for="last_name" class="label">Last name</label>
                <input type="text" class="input" id="last_name" name="last_name" v-model="lastName" :required="isRequired">
            </div>
        </div>
        <div class="field">
            <label for="company" class="label">Company (optional)</label>
            <div class="control is-expanded">
                <input type="text" class="input" id="company" name="company" v-model="company">
            </div>
        </div>
        <div class="field">
            <label for="address" class="label">Address</label>
            <div class="control is-expanded">
                <input type="text" class="input" id="address" name="address_line_1" v-model="addressLine1" :required="isRequired">
                <input type="text" class="input mt-4" id="address" name="address_line_2" v-model="addressLine2">
            </div>
        </div>
        <div class="field">
            <label for="city" class="label">City</label>
            <div class="control is-expanded">
                <input type="text" class="input" id="city" name="city" v-model="city" :required="isRequired">
            </div>
        </div>
        <div class="field">
            <label for="country" class="label">Country</label>
            <div class="select is-fullwidth">
                <select name="country" id="country" v-model="country" @change="state = ''" :required="isRequired">
                    <option :value="country.name" :key="country.sortname" v-for="country in countries">{{ country.name }}</option>
                </select>
            </div>
        </div>
        <div class="field is-grouped">
            <div class="control is-expanded">
                <label for="state" class="label">States</label>

                <div class="select is-fullwidth" v-if="states.length > 0">
                    <select name="state" id="state" v-model="state" :required="isRequired">
                        <option :value="s.name" :key="s.id" v-for="s in states">{{ s.name }}</option>
                    </select>
                </div>
                <input type="text" class="input" id="state" name="state" v-model="state" v-else :required="isRequired">
            </div>
            <div class="control is-expanded">
                <label for="postal" class="label">Postal code</label>
                <input type="text" class="input" id="postal" name="postal" v-model="postal" :required="isRequired">
            </div>
        </div>

        <div class="field">
            <div class="control is-expanded">
                <label for="phone" class="label">Phone</label>
                <input type="text" class="input" id="phone" name="phone" v-model="phone" :required="isRequired">
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: "addressForm",
    props: {
        countries: {
            type: Array,
            required: true
        },
        firstName: String,
        lastName: String,
        company: String,
        addressLine1: String,
        addressLine2: String,
        city: String,
        country: String,
        state: String,
        postal: String,
        phone: String,
        isRequired: {
            type: Boolean,
            default: true
        }
    },

    data() {
        return {
            states: []
        };
    },

    watch: {
        country(value) {
            var country = collect(this.countries).where('name', value).first();

            if (typeof country !== 'undefined'){
                this.states = country.states;
                return;
            }

            this.states = [];
        }
    }
}
</script>

<style>

</style>

but whenever i edit one of the input. vue throw that warn. the thing is, i dont want to create data property because my props is too many.

how to tackle this kind of situation? my idea is to

  1. disable vue warn and just go with the anti pattern flow
  2. pass props as array instead one by one. (but it will become ugly)

25th June, 2018

larafam left a reply on Shared Variables In Route Group • 3 weeks ago

@edwinjansen i solve this issue using view::share and middleware


Route::group(['middleware' => ['bound']], function () { .. your routes });

register bound middleware in kernel


// in Bound.php middleware

public function handle(Request $request, Closure $next)
    {
        \Illuminate\Support\Facades\View::share(
            'some_data',  'i want to share'
        );

        return $next($request);
    }

then you can use that data in that particular route group

23rd June, 2018

larafam left a reply on Async In Php • 4 weeks ago

@Cronix so what is the difference between queue worker and async stuff provide bye spatie/async or reactphp library?

larafam left a reply on Async In Php • 4 weeks ago

@NickVahalik so if i want to send 100 email, i can just do it like this

// SomeController

$pool->add(new SendHundredEmail());

return back();

right?

larafam started a new conversation Async In Php • 4 weeks ago

im currently really interested with async world, i want to move into nodejs async world, but then im too lazy to learn new stuff and stick with php (laravel).. can some one give me an async use case in php and how we tackle it with php? im thinking using spatie/async or reactphp..

22nd June, 2018

larafam left a reply on Composer • 1 month ago

@Snapey my project folder size become large:

with .git (800mb)

without .git (100mb)

larafam started a new conversation Composer • 1 month ago

how to avoid composer to include .git folder for every package that i require.

13th June, 2018

larafam left a reply on Check If Class Extend Abstract Class Problem • 1 month ago

@Cronix tq. this is my current solution


$parent = get_parent_class($instance);
        
$msg = 'Provider must extend '. Gateway::class .' abstract class.';

if (! $parent) {
    abort(403, $msg);
} else {
    $reflect = new \ReflectionClass($parent);

    if (! $reflect->isAbstract() || $parent != Gateway::class) {
        abort(403, $msg);
    }
}

12th June, 2018

larafam started a new conversation Check If Class Extend Abstract Class Problem • 1 month ago

i already google 'how to check if a class extend abstract class'. all i get is to use is_subclass_of built in function which is not work as intended. already use instanceof still return false. any alternative?

8th June, 2018

larafam left a reply on Weird Sytax In Laravel Core • 1 month ago

@tykus wow thanks. learn something new everyday.. hahaha... do u have a source (not php.net) for me to learn something like this?

larafam started a new conversation Weird Sytax In Laravel Core • 1 month ago

i saw taylor do something like this in laravel core. i dont remember it at what file.

$this['something']

access object like array?

4th June, 2018

larafam left a reply on About Service Provider In Package Dev • 1 month ago

@arukomp my problem is very weird actually haha.. might need to refactor the whole architecture... anyway, thanks alot for helping me

larafam left a reply on About Service Provider In Package Dev • 1 month ago

@arukomp actually AServiceProvider boot method is waiting for BServiceProvider boot method.. :((

larafam started a new conversation About Service Provider In Package Dev • 1 month ago

is there any way for me to make some of my package service provider to wait for other service provider??

something like this:


class AServiceProvider extends \Illuminate\Support\ServiceProvider
{
    protected $wait = BServiceProvider::class;
}

13th May, 2018

larafam started a new conversation Set Custom Timezone For Eloquent Timestamp Carbon • 2 months ago

is timestamp carbon instance timezone follow app.php timezone or default timezone specify in php.ini?

does laravel timezone in config (app.php) set date_default_timezone_set in background????

basically, i have simple timezone select form. and want to set user chosen timezone like this,


config(['app.timezone' => $timezone]);

so, THE question is, how to properly set timezone that effect eloquent timestamp and carbon(if can)?

17th April, 2018

larafam left a reply on Laravel And Ajax • 3 months ago

@bluelock yes, thats what i usually do for my ajax response. my question is when to use ajax?

larafam left a reply on Laravel And Ajax • 3 months ago

@jlrdw so basically either way is okay right?

larafam started a new conversation Laravel And Ajax • 3 months ago

when to use ajax in my application?

should i return the data at the controller like this:

return view('myview')->with('data', $data);

or use ajax to get the data???

11th April, 2018

larafam left a reply on Relationship Inside Accessor • 3 months ago

@rin4ik


<?php

namespace Shop\Model;

use Illuminate\Database\Eloquent\Model;
use Shop\Model\Product;

class Variant extends Model
{
    protected $guarded = [];

    protected $appends = [
        'title_with_variants'
    ];

    public function product()
    {
        return $this->belongsTo(Product::class, 'product_id', 'id');
    }

    public function getTitleWithVariantsAttribute()
    {
        $postTitle = '';

        if($this->product->product_type == 'variable'){
            $postTitle = ' ('. implode(', ', $this->variants) .')';
        }

        return "{$this->product->title} {$postTitle}";
    }
}

larafam left a reply on Relationship Inside Accessor • 3 months ago

@rin4ik im sorry. its Variant.php not Product.php

1 product has many variant. so in variant i want to access its product,.

larafam started a new conversation Relationship Inside Accessor • 3 months ago

below snippet throw 500 error!

// model: Product.php


    public function getTitleWithVariantsAttribute()
    {
        $postTitle = '';

        if($this->product->product_type == 'variable'){
            $postTitle = ' ('. implode(', ', $this->variants) .')';
        }

        return "{$this->product->title} {$postTitle}";
    }


so how can i access $this->product (relationship) inside accessor ?

larafam left a reply on Json Response Question • 3 months ago

@rin4ik

so basically second way is more appropriate??

larafam started a new conversation Json Response Question • 3 months ago

what is the differences???


//between

return [
    'test' => 'hello world'
];

//and

return response()->json([
    'test' => 'hello world'
]);


6th March, 2018

larafam started a new conversation Is There Any Package That Solve Multiple Form Submission Issues? • 4 months ago

is there any laravel package that solve this issue in server side (not client pls). is anyone here know?

24th February, 2018

larafam left a reply on Modify Appended Property • 4 months ago

omg thanks @Snapey

larafam started a new conversation Modify Appended Property • 4 months ago

the title says it all.

// mymodel.php

protected $appends = [
    'custom'
];

public function getCustomAttribute(){
    return 'foo';
}


$model = mymodel::find(1);

$model->custom = 'new value'; //not working
$model->setAttribute('custom', 'new value'); //not working

echo $model->custom; // foo (expecting new value)

is there any way that i can change the value??

9th February, 2018

larafam left a reply on Required If Coupon != 0 • 5 months ago

there is required_if rule in docs. im not sure if thats what u want,.

5th February, 2018

larafam left a reply on Weird Api Behaviour Or Am I Stupid? Halp! • 5 months ago

@shez1983 using postman i get intended result, but not from client controller. its seems that


return Post::all(); 

is called from client server not remote server. hm

larafam started a new conversation Weird Api Behaviour Or Am I Stupid? Halp! • 5 months ago

client.com has no post, remote.com has a post, but when i request from remote, i got zero post, it should return a post, why is this happening??? lets consider this scenario.


// client.com
Route::get('/request/to/client/controller', '[email protected]');


// SomeController
public function getDataFromRemote(){

    $response = (new \GuzzleHttp\Client)->request('post', '//remote.com/api/data');

    echo $response->getBody(); // return [] (should have a result)

}



// remote.com

// api
Route::post('/data', '[email protected]');


// SomeController
public function fetchPost(){

    return Post::all(); 

}

please halp!

1st February, 2018

larafam left a reply on Analytics But Not From Google Analytics. Anyone? • 5 months ago

@martinbean suggestion seems nice. i didnt realize google analytics have users management until u mentioned. thanks.

@AviationCode thanks for the response. im hoping for small package that track my client website like

31st January, 2018

larafam started a new conversation Analytics But Not From Google Analytics. Anyone? • 5 months ago

is there any php/laravel analytics packages that i can use for my websites? i dont want to use google analytics because i dont want my client to go through google analytics setup process.

18th January, 2018

larafam left a reply on About Event! • 6 months ago

how to run a benchmark @Cronix

17th January, 2018

larafam started a new conversation About Event! • 6 months ago

im heavily use event on my laravel apps. registering a listener on hundreds of event. is it expensive operation? is it ok?

larafam left a reply on How To Parse In Javascript . • 6 months ago

10th January, 2018

larafam started a new conversation Best Practice? • 6 months ago

i always use app() helper to resolve any class that i want to use in controller/class/view;

is it a best practice to use it all the time?

9th January, 2018

larafam left a reply on Model Refer To Itself, Help! • 6 months ago

apprently i cant use accessor like this:


public function getSomethingAttribute()
    {
        return $this->submenus();
    }

larafam started a new conversation Model Refer To Itself, Help! • 6 months ago

let say i have table 'menu', where it will store menu type 'parent' and 'child'.

when i want to create a relationship with refering to current model, i got errors:

[Wed Jan 10 08:14:38 2018] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 16384 bytes) in C:\xampp\htdocs\project\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 330

[Wed Jan 10 08:14:38 2018] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in C:\xampp\htdocs\project\vendor\symfony\debug\Exception\FatalErrorException.php on line 1

my model code:


class Menu extends Model
{

    /*
    |--------------------------------------------------------------------------
    | Relationship
    |--------------------------------------------------------------------------
    */
   
    public function submenus()
    {
        return $this->hasMany(Menu::class, 'slug', 'id')->orderBy('order', 'asc');
    }

}

how to do this correctly?

7th January, 2018

larafam left a reply on Want To Ask About Gmail! Halp! • 6 months ago

@sutherland ohhh i see.. thanks mate!

larafam left a reply on Want To Ask About Gmail! Halp! • 6 months ago

@sutherland is that mean my university (not school sorry) pay $5 for each student every month?

larafam started a new conversation Want To Ask About Gmail! Halp! • 6 months ago

my school provide an email username, eg: [email protected]

and i can login that email using gmail.

how is this possible? what is step to achieve this?

let say i own a domain and hosting. whats next?

pls enlighten me

31st December, 2017

larafam left a reply on How To Do Use Variable As Global In Controller ? • 6 months ago

i think u only need to create a method for that.



class CartController extends Controller
{

    public function getCart()
    {
        $cart = $this->fetchCart();
        return view('frontend.cart.cart', compact('cart'));
    }

    public function postAddProduct($id)
    {
        $product = Product::find($id)->first();
        
    $cart = $this->fetchCart();

        return back()
            ->with('message','Ürün sepetinize eklendi')
            ->with('message_status','success');
    }

    public function fetchCart(){
    return Cart::where('user_id', \Auth::id())->first();
    }
}


larafam left a reply on How To Do Use Variable As Global In Controller ? • 6 months ago

maybe you can assign it into session.

https://laravel.com/docs/5.5/session

larafam left a reply on Accept Only Gmail ID While Registering L5.5 • 6 months ago

maybe you can make a simple check the email field before create the model


if(strpos($data['email'], '@gmail') == false){

    throw new HttpResponseException(back()->with('errors', 'Email must be gmail!'));

}


or you can create a custom validator for that

30th December, 2017

larafam left a reply on How Should I Create Automatic Update For My Application? • 6 months ago

@topvillas how to do it on shared hosting..

larafam started a new conversation How Should I Create Automatic Update For My Application? • 6 months ago

i developed a super lite laravel cms that user will install on their hosting. let say i want to update those cms that i distributed. my idea is:

each cms will run cron job every minute in background that check new version from official repo site.

if new version exist.

2.1 download new version (.zip)

2.2 replace old with new

is this the best way? if its not, can anyone show the best practice on how to roll out new update? halp!

23rd December, 2017

larafam started a new conversation About Auto Discovery In Laravel 5.5 • 6 months ago

i want to conditionally attach and detach some package. The objective is to make my package modular and act like wordpress plugins.

my idea is to conditionally append and pop the package in bootstrap/cache/packages.php.

is my idea plausible?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.