I am trying to execute simple CRUD operation using laravel. but it gives an error code 500 , when I try to fetch data from table either by laravel framework as well as with plain PHP.
Here is my controller class.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\BookModel;
class AdminController extends Controller
{
function getItems()
{
$conn = new mysqli('****', '****', '****', '****');
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM book";
$result = $conn->query($sql);
// $data = DB::select('select * from book');
//$data = BookModel::all();
return $result;
}
}
My js code , which makes call to controller.
myObject1 = new Vue({
el: '#Admin',
data: {
test:'hey',
books:[],
newBook : {bookName:'',autherName:''},
},
methods:{
getBooks : function(){
_this=this;
axios.get('getAllBooks').then(function (Response){
_this.books=Response.data;
})
}
},
created:function(){
this.getBooks();
}
})
Error:
spread.js:25 GET http://localhost/lara-vue-login/public/main/getAllBooks 500 (Internal Server Error)
(anonymous) @ spread.js:25
e.exports @ spread.js:25
e.exports @ spread.js:25
Promise.then (async)
r.request @ spread.js:25
r.<computed> @ spread.js:25
(anonymous) @ axios.min.js:477
getBooks @ admin.js:13
(anonymous) @ vue.min.js:6
created @ admin.js:19
t._callHook @ vue.min.js:6
Tt.t._init @ vue.min.js:6
di @ vue.min.js:7
(anonymous) @ admin.js:1
spread.js:25 Uncaught (in promise) Error: Request failed with status code 500
at e.exports (spread.js:25)
at e.exports (spread.js:25)
at XMLHttpRequest.d.onreadystatechange (spread.js:25)
axiom , which is been used. ---> "https://unpkg.com/axios/dist/axios.min.js"
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire