Skip to content

Instantly share code, notes, and snippets.

@bayareawebpro
Last active November 16, 2017 17:29
Show Gist options
  • Save bayareawebpro/f617b814ee7d0391787c80dfcf5913f0 to your computer and use it in GitHub Desktop.
Save bayareawebpro/f617b814ee7d0391787c80dfcf5913f0 to your computer and use it in GitHub Desktop.
Model Vue Props Example
<?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