Last active
November 16, 2017 17:29
-
-
Save bayareawebpro/f617b814ee7d0391787c80dfcf5913f0 to your computer and use it in GitHub Desktop.
Model Vue Props Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Your Model | |
protected $appends = [ | |
'vue_props', | |
]; | |
//Props Ancestor Attribute | |
public function getVuePropsAttribute(){ | |
$props = (object) array(); | |
//User | |
$props->user = request()->user(); | |
//Routes | |
$props->routes = (object) array( | |
'dashboard' => route('user.dashboard'), | |
'edit' => route('user.edit') | |
); | |
//Settings | |
$props->settings = (object) array( | |
'sidebar_left' => false, | |
'sidebar_right' => true, | |
'active_tab' => 'some-tab' | |
); | |
return json_encode($props); | |
} | |
?> | |
<my-component :my_model="{{ $model->vue_props }}"></my-component> | |
<script> | |
export default{ | |
name:'my-component', | |
props: ['my_model'], | |
methods: { | |
doSomething : function() { | |
let someVar = this.my_model.routes.dashboard; | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment