, vue-resource adlı bir eklenti ile vuejs ajax çağrısı kullanarak bir veritabanından veri almaya çalışıyor. Maalesef, json veri nesnesi, veritabanından gerçek verileri değil, html sayfasını içerir. Birisi bana neyi yanlış yaptığımı söyleyebilir mi?Vuejs ajax GET isteği, verileri Laravel 5.1 Blade şablonunda döndürmüyor.
<?php
Route::get('find', '[email protected]');
fruitsctrl.php (kontrol)
routes.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Fruit;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class FruitsCtrl extends Controller
{
public function index(Request $req){
$fruits = Fruit::all();
return view('fruitsHome', $fruits);
}
}
fruit.php (model)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Fruit extends Model
{
protected $fillable = [
'id', 'name', 'type'
];
}
fruitshome.blade: Benim kodudur. php (görünüm)
Ayrıca böyle indeks yöntemi güncellemeniz gerekirclass Fruit extends Model
{
protected $table = 'fruits';
protected $fillable = [
'id', 'name', 'type'
];
}
:
<head>
<meta id="token" content="{{ csrf_token() }}">
</head>
<body>
<div class="row" id="vapp">
<ul>
<li v-for="fruit in fruits">
@{{ fruit.name }}
@{{ fruit.type }}
</li>
</ul>
</div>
<body>
app.js (javascript)
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('content');
var v = new Vue({
el : "#vapp",
ready :function() {
this.fetchFruits();
},
data : {
fruit : {id:'', name:'', type:''},
fruits : []
},
methods : {
fetchFruits : function(){
this.$http.get('/find').then(function(res){
this.fruits = res;
},function (data){
console.log(error ...);
});
}
}
});
Cevabınız için teşekkür ederiz. Önerinizi denedim ama işe yaramıyor. \ View \ View.php'yi aydınlatırken bir hata istisnası alıyorum. Hata yasadışı ofset tipidir ... – DBoonz