selectボックスに表示されるcategoryを表示させたいのですが、表示されません。
(セレクトボックスのボタンを押すと、神社・寺が表示されます。)
PostControllerに下記の通り、use App\Post,use App\Model\Postと書き加えているのですが、上記のエラーが解消されません。アドバイスをいただきたいです。
laravelのlogにはlocal.ERROR: Class 'App\Model\Post' not found {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Class 'App\Model\Post' not found at /Users/maru/develop/naratabi/src/app/Http/Controllers/PostController.php:104)
と表記されています。
larevel
1PostController.php 2 22 use App\Model\Post; 3 4 96 public function index(Request $request) 5 97 { 6 98 $category = Category::all(); 7 99 return response()->json(['categories'=>$category],200); 8101 } 9102 public function find(Request $request,$id) 10103 { 11104 $posts= Post::where('category_id',$request->id)->get(); 12105 13106 return response()->json(['posts'=>$posts],200); 14107 }
laravel
1Post.php 2 3<?php 4 5namespace App\Http\Controllers; 6 7use Illuminate\Database\Eloquent\Model; 8 9class Post extends Model 10{ 11 public function posts() 12 { 13 return $this->hasMany('App\Models\Post'); 14 } 15} 16
nuxt
1index.vue 2 3<template> 4<div class="container"> 5 <div class="title"> 6 <p>鹿と大仏だけじゃない奈良を知る</p> 7 </div> 8 <div class="slider_outer"> 9 <transition name="fade"> 10 <div class="slider-inner" :key="idx" v-for="(image, idx) in images" v-if="current_slide == idx"> 11 <img class="slider-inner" v-bind:src="images[idx].img" :key="images[idx].img" width="450" height="300"> 12 </div> 13 </transition> 14 </div> 15 <div class="category_search_form"> 16 <div class="select_title"> 17 <p>下記ボタンをクリックして検索しよう</p> 18 <select v-model="category_id" v-on:change="jump(category_id)" class="select"> 19 <option value="">category</option> 20 <option v-for="category in categories" :value= "category.id" > 21 {{category.id}} 22 {{ category.name}} 23 </option> 24 </select> 25 </div> 26 </div> 27 <div class="image_post"> 28 <div class="photoshow"> 29 <NuxtLink to="/show"> 30 <div class="post"> 31 写真一覧をみる 32 </div> 33 </NuxtLink> 34 <NuxtLink to="/form"> 35 <div class="photoshowtitle"><a>奈良の写真を投稿する!</a></div> 36 </NuxtLink> 37 </div> 38 </div> 39</div> 40 41</template> 42 43<script> 44import axios from 'axios'; 45export default{ 46data(){ 47 return{ 48 category_id:'', 49 category_name:'', 50 categories:[], 51 category:[], 52 post:[], 53 id:'', 54 name:'', 55 current_slide:0, 56 images:'', 57 images:[ 58 {img:'https://naratabi.s3.ap-northeast-1.amazonaws.com/images/shika.JPG'}, 59 {img:'https://naratabi.s3.ap-northeast-1.amazonaws.com/images/oomiwa.JPG'}, 60 {img:'https://naratabi.s3.ap-northeast-1.amazonaws.com/images/BqWJ6Maew497TkYq1oBBkuibneoMO0ERGZWKXJtu.jpeg'}, 61 ], 62 } 63}, 64 created(){ 65 //axios.get(`http://127.0.0.1:8000/api/posts`) 66//.then(response => { 67// this.categories = response.data.categories 68 //console.log(response.data) 69 //}); 70 this.getCategories() 71 72 }, 73 mounted() { 74 setInterval(() => { 75 this.current_slide = this.current_slide < this.images.length -1 ? this.current_slide +1 : 0 76 }, 6000), 77 console.info('this.$axios.defaults.baseURL:', this.$axios.defaults.baseURL) 78}, 79 methods:{ 80 getCategories: function(){ 81 this.$axios.$get(`/category`) 82.then(response => { 83 console.log(response) 84 this.categories = response.catagories 85 console.log(response.data) 86 }); 87 }, 88 jump:function(id){ 89 this.$router.push({ path: `category/${id}`}); 90 console.log(id) 91 }, 92 slideshow(images) { 93 const current = images[this.index]; 94 const prev = images[this.index - 1] ? images[this.index - 1] : images[images.length - 1]; 95 current.classList.add('fadein'); 96 current.classList.remove('fadeout'); 97 prev.classList.remove('fadein'); 98 prev.classList.add('fadeout'); 99 } 100 101 }, 102 103} 104</script> 105 106 107
laravel
1api.php 2Route::get('/category','PostController@index'); 3Route::get('/category/{id}','PostController@find'); 4 5
回答2件
あなたの回答
tips
プレビュー