我一直在尝试将数据保存在数据库中,但此错误不断出现:
(2/2) QueryException
SQLSTATE[HY000] [2002] Connection refused (SQL: insert into `stores` (`name`, `description`) values (El café de mi esquina , Es lindo))
这是控制器上的代码:
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store()
{
$nuevoLocal= new Store();
$nuevoLocal->name="El café de mi esquina ";
$nuevoLocal->description="Es lindo";
$nuevoLocal-> save();
}
网络:
Route::get('/agregarNegocio', "storeController@store");
模型:
命名空间应用程序;
use Illuminate\Database\Eloquent\Model;
class store extends Model
{
public $guarded =[];
public $timestamps=false;
}
环境:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cafe
DB_USERNAME=root
DB_PASSWORD=root
db 名称是 cafe,它有一个表存储,其中包含 ID(主键)、名称和描述
如果一个 put var_dump($nuevoLocal); 出口; 就在 save() 之前,这就是我得到的:
object(App\store)#158 (25) { ["guarded"]=> array(0) { } ["timestamps"]=> bool(false) ["connection":protected]=> NULL ["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["incrementing"]=> bool(true) ["with":protected]=> array(0) { } ["withCount":protected]=> array(0) { } ["perPage":protected]=> int(15) ["exists"]=> bool(false) ["wasRecentlyCreated"]=> bool(false) ["attributes":protected]=> array(2) { ["name"]=> string(23) "El café de mi esquina " ["description"]=> string(8) "Es lindo" } ["original":protected]=> array(0) { } ["casts":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["appends":protected]=> array(0) { } ["events":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["fillable":protected]=> array(0) { } }
30秒到达战场
叮当猫咪