質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

解決済

2回答

1727閲覧

Laravel viteにてjavascriptをviewに読み込ませたいが、エラー ($string) must be of type string, array givenが表示される

enoshi

総合スコア3

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

0クリップ

投稿2023/05/01 13:06

実現したいこと

  • laravel viteにてjavascriptをviewに読み込ませて、動作させたい

前提

laravel10でLINEアプリと連携したWebシステムを作っています。
一覧画面で、bodyがonload時に変更ボタンと削除ボタンを無効化させるjavascriptをviewに読ませようとしましたが、うまく行かず、サードパーティーのviteプラグインをインストールしてみたら競合して以下のエラーが出るようになりました。

発生している問題・エラーメッセージ

htmlspecialchars(): Argument #1 ($string) must be of type string, array given

該当のソースコード

base.blade.php

1<html> 2 <head> 3 @vite(['resources/css/app.css', 'resources/js/app.js']) 4 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> 5 <title>@yield('title')</title> 6 <style> 7 body, table {font-size:20pt; font-family: sans-serif, Verdana, Roboto, "Droid Sans", "游ゴシック", YuGothic, "メイリオ", Meiryo, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", "MS Pゴシック";} 8 //label { border-left :solid 5px green; padding: 10px;} 9 label { border-left :solid 5px @yield('label_color'); padding: 10px;} 10 h1 { font-size:30pt;} 11 .menutitle { font-size:14pt; font-weight:bold; margin: 0px;} 12 .content {margin:10px;} 13 .footer { text-align: center; font-size: 20pt; margin: 10px; color: @yield('label_color');} 14 .btn {font-size: 20pt; height: 50px;} 15 .err {color: red;} 16 .require {font-size: 15pt; color: red;} 17 input.geomsize { 18 width: 1.0em; 19 height: 1.0em; 20 } 21 .menu {width: 430px;} 22 .subtitle { background: @yield('th_color'); color:#fff;} 23 @if ( $isBorder == true) 24 .table-wrap{ 25 overflow-x:scroll; 26 overflow-y:scroll; 27 } 28 table{ 29 padding:3px; 30 border:1px solid #000; 31 border-collapse: collapse; 32 //table-layout: fixed; 33 //width: 100%; 34 } 35 th, td{ 36 padding:3px; 37 border:1px solid #000; 38 white-space: nowrap; 39 } 40 th{ 41 //background: #90ee90; 42 background: @yield('th_color'); 43 } 44 #table tr:nth-child(even) td { 45 background-color: #eee; 46 } 47 @else 48 th, td{ 49 padding:5px; 50 } 51 @endif 52 </style> 53 </head> 54 55 <body onload="start()"> 56 @switch($panel) 57 @case(config('setting.panel-green')) 58 <div class="panel panel-success"> 59 @break 60 @case(config('setting.panel-blue')) 61 <div class="panel panel-primary"> 62 @break 63 @default 64 <div> 65 @break 66 @endswitch 67 <div class="panel-heading"> 68 <h1>@yield('title')</h1> 69 </div> 70 @if (session()->has('success')) 71 <div class="alert alert-success"> 72 {!! session()->get('success') !!} 73 </div> 74 @elseif (session()->has('exclusive_lock_error')) 75 <div class="alert alert-danger"> 76 {{ session()->get('exclusive_lock_error') }} 77 </div> 78 @elseif (session()->has('no_change_error')) 79 <div class="alert alert-success"> 80 {{ session()->get('no_change_error') }} 81 </div> 82 @endif 83 @section('menubar') 84 <div class="panel-body"> 85 <div class="content"> 86 @yield('content') 87 </div> 88 </div> 89 <div class="footer"> 90 @yield('footer') 91 © Copyright 2023 xxダンスフェスティバル All rights reserved. 92 </div> 93 </div> 94 </body> 95</html> 96

circleShow.blade.php

1@extends('layouts.base') 2 3@section('title', '団体照会') 4 5@section('menuber') 6 @parent 7 団体照会 8@endsection 9 10@section('content') 11 @section('label_color','green') 12 <form action="/circle/show" method="post" name="myForm"> 13 @csrf 14 <input type="hidden" name="userId" value="{{ $userId }}"> 15 <input type="hidden" name="destination" value="{{ $destination }}"> 16 <input type="hidden" name="isAuthority" value="{{ $isAuthority }}"> 17 @section('th_color', config('setting.th-color-green')) 18 @php 19 $member_categorys = array( 20 1 => "未就学児童", 21 2 => "小学生", 22 3 => "中学生", 23 4 => "高校生", 24 5 => "大学生", 25 6 => "大人" 26 ); 27 @endphp 28 <div class="table-wrap"> 29 <table id="table"> 30 <tr> 31 <th>選択</th> 32 <th>団体名</th> 33 <th>ダンスの種類</th> 34 <th>参加者</th> 35 <th>参加人数</th> 36 <th>代表者氏名</th> 37 <th>郵便番号</th> 38 <th>住所</th> 39 <th>携帯電話番号</th> 40 <th>電話番号</th> 41 <th>FAX番号</th> 42 <th>メールアドレス</th> 43 </tr> 44 <tbody id="tbody"> 45 @foreach ($circles as $circle) 46 <tr> 47 <td> 48 <input type="radio" class="geomsize" name="circle_id" id="{{$circle->id}}" value="{{ $circle->id }}" onchange="selectedRadio()"> 49 </td> 50 <td> {{ $circle->circle_name }} </td> 51 <td> {{ $circle->genre }} </td> 52 @php 53 $arrCategory = explode(",", $circle->member_category); 54 $strCategory = ''; 55 @endphp 56 57 @foreach ($member_categorys as $id => $value) 58 @if (in_array($id, $arrCategory)) 59 @php 60 $strCategory .= $value . "・"; 61 @endphp 62 @endif 63 @endforeach 64 @php 65 $strCategory = mb_substr($strCategory, 0, mb_strlen($strCategory) - 1); 66 @endphp 67 <td> {{ $strCategory }} </td> 68 <td> {{ $circle->circle_number_of_people }} </td> 69 <td> {{ $circle->representative_lastname }} {{ $circle->representative_firstname }}</td> 70 <td> {{ $circle->zipcode }} </td> 71 @php 72 $strAddress = $circle->prefecture_name . $circle->city_name . $circle->town_name . $circle->block . " " . $circle->building_name; 73 @endphp 74 <td> {{ $strAddress }} </td> 75 <td> {{ $circle->mobile_tel }} </td> 76 <td> {{ $circle->house_tel }} </td> 77 <td> {{ $circle->fax_no }} </td> 78 <td> {{ $circle->email_address }} </td> 79 </tr> 80 @endforeach 81 </tbody> 82 </table> 83 </div> 84 <br> 85 <input class="btn btn-success" type="submit" name="submitBtn_edit" id="submitBtn_edit" value="変更"> 86 <input class="btn btn-success" type="submit" name="submitBtn_delete" id="submitBtn_delete" value="削除"> 87 <input class="btn btn-success" type="submit" name="submitBtn_back" value="戻る"> 88 89 </form> 90@endsection 91 92@section('footer') 93@endsection 94

resources/js/app.js

1import './bootstrap'; 2 3 4 document.getElementById("submitBtn_edit").disabled = "disabled"; 5 document.getElementById("submitBtn_delete").disabled = "disabled";

package.json

1{ 2 "private": true, 3 "scripts": { 4 "dev": "vite", 5 "build": "vite build" 6 }, 7 "devDependencies": { 8 "@vitejs/plugin-vue": "^4.2.1", 9 "axios": "^1.1.2", 10 "laravel-vite-plugin": "^0.7.2", 11 "vite": "^4.0.0" 12 }, 13 "dependencies": { 14 "create-vite": "^4.3.1" 15 } 16}

試したこと

以下を参考にサードパーティーのプラグインをアンインストールしましたが、結果は同じでした。
https://github.com/laravel/vite-plugin/issues/65

補足情報(FW/ツールのバージョンなど)

laravel 10.6.2
PHP 8.1.12
XAMPP v3.3.0
ngrok

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

aravel/uiをインストールすることで自己解決しました。
アンインストールしたはずの競合するパッケージinnocenzi/laravel-viteがこれによりきれいにリムーブされたようです。

C:\Users>composer require laravel/ui Info from https://repo.packagist.org: #StandWithUkraine ./composer.json has been updated Running composer update laravel/ui Loading composer repositories with package information Updating dependencies Lock file operations: 1 install, 0 updates, 2 removals - Removing innocenzi/laravel-vite (v0.3.1) - Removing spatie/laravel-package-tools (1.15.0) - Locking laravel/ui (v4.2.1) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 1 install, 0 updates, 2 removals - Removing spatie/laravel-package-tools (1.15.0) - Removing innocenzi/laravel-vite (v0.3.1) - Installing laravel/ui (v4.2.1): Extracting archive Generating optimized autoload files > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover --ansi INFO Discovering packages. barryvdh/laravel-debugbar ..................................................................................... DONE laravel/sail .................................................................................................. DONE laravel/sanctum ............................................................................................... DONE laravel/tinker ................................................................................................ DONE laravel/ui .................................................................................................... DONE linecorp/line-bot-sdk ......................................................................................... DONE nesbot/carbon ................................................................................................. DONE nunomaduro/collision .......................................................................................... DONE nunomaduro/termwind ........................................................................................... DONE spatie/laravel-ignition ....................................................................................... DONE 81 packages you are using are looking for funding. Use the `composer fund` command to find out more! > @php artisan vendor:publish --tag=laravel-assets --ansi --force INFO No publishable resources for tag [laravel-assets]. Found 1 security vulnerability advisory affecting 1 package. Run composer audit for a full list of advisories. Using version ^4.2 for laravel/ui

投稿2023/05/02 11:14

enoshi

総合スコア3

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

エラー内容としては、「引数がString(文字列)でなくてはならないのにArray(配列)になっているよ」ということです。
確認すべき箇所がいくつかあるようですので、下記URLを参考に上から順番に実施していけば直るかもしれません。
https://biz.addisteria.com/laravel-vite-error-htmlspecialchars/

投稿2023/05/02 06:34

Mash

総合スコア40

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

enoshi

2023/05/02 07:40

ご回答ありがとうございます。 すでにinnocenzi/laravel-viteをアンインストールしており、キャッシュもクリアしましたが状況変わらずでした。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問