I created a form to update the role model but on clicking on the save button, it does not appear to submit to the controller method. Even the validation errors message does not appear if the name input field is invalid. Below you can find the code used for the form.
Form:
{!! Form::model($role, ['route' => ['roles.update', $role->id], 'method' => 'put']) !!}
#include('roles.fields')
{!! Form::close() !!}
The fields for the form are:
<!-- Name Field -->
<div class="form-group col-sm-6">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
</div>
<!-- Display Name Field -->
<div class="form-group col-sm-6">
{!! Form::label('display_name', 'Display Name:') !!}
{!! Form::text('display_name', null, ['class' => 'form-control']) !!}
</div>
<!-- Description Field -->
<div class="form-group col-sm-12 col-lg-12">
{!! Form::label('description', 'Description:') !!}
{!! Form::textarea('description', null, ['class' => 'form-control', 'rows' => '5']) !!}
</div>
<!-- Submit Field -->
<div class="form-group col-sm-12">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
Cancel
</div>
Request:
namespace App\Http\Requests;
use App\Http\Requests\Request;
use App\Models\Role;
class UpdateRoleRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return Role::$rules;
}
}
Controller:
/**
* Update the specified Role in storage.
*
* #param int $id
* #param UpdateRoleRequest $request
*
* #return Response
*/
public function update($id, UpdateRoleRequest $request)
{
$role = $this->roleRepository->findWithoutFail($id);
if (empty($role)) {
Flash::error('Role not found');
return redirect(route('roles.index'));
}
$role = $this->roleRepository->update($request->all(), $id);
Flash::success('Role updated successfully.');
return redirect(route('roles.index'));
}
Model:
<?php
namespace App\Models;
use Eloquent as Model;
use Zizaco\Entrust\EntrustRole;
use Illuminate\Database\Eloquent\SoftDeletes;
class Role extends EntrustRole
{
use SoftDeletes;
public $table = 'roles';
protected $dates = ['deleted_at'];
public $fillable = [
'name',
'display_name',
'description'
];
/**
* The attributes that should be casted to native types.
*
* #var array
*/
protected $casts = [
'name' => 'string',
'display_name' => 'string'
];
/**
* Validation rules
*
* #var array
*/
public static $rules = [
'name' => 'required|unique:roles'
];
}
Please help if possible. Thanks!
You cant use put as the form method. Read the documentation about method spoofing in laravel
{!! Form::model($role, ['route' => ['roles.update', $role->id], 'method' => 'post']) !!}
<input type="hidden" name="_method" value="PUT">
#include('roles.fields')
{!! Form::close() !!}
For those people that work with HTML and laravel 5.2:
<form method="post" ... > {{ method_field('PUT') }} ... </form>
Hope this help people.
Related
When I register a new user sign up, it save the password to database with hashed password. But when I go edit the user from the admin dashboard, the edit function work perfectly, but the password did not store or save as a hashed password, it save as plain text.
This is link to image show in database modification
This is the userController:
public function edit($id)
{
$user = $this->userRepository->find($id);
if (empty($user)) {
Flash::error('User not found');
return redirect(route('users.index'));
}
return view('users.edit')->with('user', $user);
}
/**
* Update the specified User in storage.
*
* #param int $id
* #param UpdateUserRequest $request
*
* #return Response
*/
public function update($id, UpdateUserRequest $request)
{
$user = $this->userRepository->find($id);
if (empty($user)) {
Flash::error('User not found');
return redirect(route('users.index'));
}
$user = $this->userRepository->update($request->all(), $id);
Flash::success('User updated successfully.');
return redirect(route('users.index'));
}
This is my fields.blade.php:
<!-- Name Field -->
<div class="form-group col-sm-6">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
</div>
<!-- Email Field -->
<div class="form-group col-sm-6">
{!! Form::label('email', 'Email:') !!}
{!! Form::email('email', null, ['class' => 'form-control']) !!}
</div>
#push('scripts')
<script type="text/javascript">
$('#email_verified_at').datetimepicker({
format: 'YYYY-MM-DD HH:mm:ss',
useCurrent: true,
sideBySide: true
})
</script>
#endpush
<!-- Password Field -->
<div class="form-group col-sm-6">
{!! Form::label('password', 'Password:') !!}
{!! Form::password('password', ['class' => 'form-control']) !!}
</div>
<!-- Role Id Field -->
<div class="form-group col-sm-6">
{!! Form::label('role_id', 'Role Id:') !!}
{!! Form::number('role_id', null, ['class' => 'form-control']) !!}
</div>
<!-- Submit Field -->
<div class="form-group col-sm-12">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
Cancel
</div>
Another thing: I'm using infyom Laravel generator.
This is the register controller (I make it by command make:auth):
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
This is the userRepository code:
<?php
namespace App\Repositories;
use App\Models\User;
use App\Repositories\BaseRepository;
/**
* Class UserRepository
* #package App\Repositories
* #version June 23, 2020, 3:11 pm UTC
*/
class UserRepository extends BaseRepository
{
/**
* #var array
*/
protected $fieldSearchable = [
'name',
'email',
'password',
'role_id'
];
/**
* Return searchable fields
*
* #return array
*/
public function getFieldsSearchable()
{
return $this->fieldSearchable;
}
/**
* Configure the Model
**/
public function model()
{
return User::class;
}
}
Add the update method to the UserRepository
protected function update(array $data,$id)
{
return User::where($id)->update([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
When trying to store an entry in my Database using Eloquent ORM i am getting the error,
Illuminate\Database\QueryException thrown with message "SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (SQL: insert into `animals` (`updated_at`, `created_at`) values (2019-04-25 22:35:47, 2019-04-25 22:35:47))"
However in my migrations i never specify name as being default as it is required.
My AnimalsController class.
public function create()
{
return view('animals.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$animal = Animal::create([
$request->input()
]);
// $animal = new Animal;
// $animal->name = $request->name;
// $animal->dob = $request->dob;
// $animal->description = $request->description;
// $animal->image = $request->image;
// $animal->available = $request->available;
//
// echo $request->id;
// echo "test";
// echo $animal->id;
// flash('Animal Added')->success();
return redirect()->route('animals.show')->with('animal', $animal);
}
/**
* Display the specified resource.
*
* #param \App\Animal $animal
* #return \Illuminate\Http\Response
*/
public function show(Animal $animal)
{
return view('animals.show')->with('animal', $animal);
}
Animal.php
class Animal extends Model
{
use SoftDeletes;
protected $dates = [
'created_at',
'updated_at'
];
/**
* Set the Attributes which are alllowed
* to be assigned
*/
protected $fillable = [
'name',
'dob',
'description',
'image',
'available'
];
create.blade.php - Where the form data is entered
<div class="row">
<div class="col">
{!! Form::open(['route' => 'animals.store'], ['class' => 'form', 'files' => true]) !!}
<div class="form-group">
{!! Form::label('name', 'Animal Name', ['class' => 'control-label']) !!}
{!! Form::text('name', null, ['class' => 'form-control input-lg', 'placeholder' => 'Waffles']) !!}
</div>
<div class="form-group">
{!! Form::label('dob', "DOB", ['class' => 'control-label']) !!}
{!! Form::date('dob') !!}
</div>
<div class="form-group">
{!! Form::label('description', "Description", ['class' => 'control-label']) !!}
{!! Form::textarea('description', null, ['size' => '20x3', 'class' => 'form-control input-lg', 'placeholder' => 'Describe the animal']) !!}
</div>
<div class="form-group">
{!! Form::label('image', "Image", ['class' => 'control-label']) !!}
{!! Form::file('image') !!}
</div>
<div class="form-group">
{!! Form::label('available', "Available", ['class' => 'control-label']) !!}
{!! Form::checkbox('available', 'value') !!}
</div>
<div class="form-group">
{!! Form::submit('Add Animal', ['class' => 'submit btn btn-info btn-lg', 'style' => 'width: 100%']) !!}
</div>
{!! Form::close() !!}
</div>
CreateAnimalsTable migration
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAnimalsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('animals', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 20);
$table->date('dob');
$table->mediumText('description');
$table->string('image');
$table->boolean('available')->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('animals');
}
}
And in case it's worth anything my show.blade.php file.
<div class="container">
<div class="row">
<div class="col-xl-12 text-center">
<p class="text-primary" style="margin-top:100px;">{{ $animal->name }} has animal ID #{{ $animal->id }}. Date: {{ $animal->dob }}</p>
</div>
</div>
</div>
I have played around for hours trying to get this to work and i am painfully blind to the solution.
I should probably also mention that if i use this code
public function store(Request $request)
{
// $animal = Animal::create([
// $request->input()
// ]);
$animal = new Animal;
$animal->name = $request->name;
$animal->dob = $request->dob;
$animal->description = $request->description;
$animal->image = $request->image;
$animal->available = $request->available;
echo $request->id;
echo "test";
echo $animal->id;
// flash('Animal Added')->success();
return redirect()->route('animals.show')->with('animal', $animal);
}
I instead get this error.
Illuminate\Routing\Exceptions\UrlGenerationException thrown with message "Missing required parameters for [Route: animals.show] [URI: animals/{animal}]."
Which i have also had no use fixing, i am using a resource in the web.php file
Route::resource('animals', 'AnimalsController');
This led me to believe that $fillable was not working as intended and instead used the above method, however it still didn't work.
If i do make Name default in the Schema i will then have to give every other attribute a default value, which i don't want to do.
Hopefully i have given enough information to be of use, thank you :D
I found two issues in this.
First, I dont think this is gonna work
$animal = Animal::create([
$request->input()
]);
This is an array wrapped inside another array. Instead, lets write:
$animal = Animal::create($request->input());
Or:
$animal = Animal::create($request->all());
In the second example, I think an animal is created, but redirected route is not specified correctly:
return redirect()->route('animals.show')->with('animal', $animal);
Let's say:
return redirect()->route('animals.show', $animal->id);
I am new to laravel and I am trying to update to profile of the user who logged in. The error says:
Class App\Http\Request\UpdateApplicantRequest does not exist
But I imported it in the top of my controller.
HomeController.php
<?php
namespace App\Http\Controllers\Applicant;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Repositories\ApplicantsRepository;
use Flash;
use Response;
use App\Models\Applicant;
use App\Http\Request\UpdateApplicantRequest;
class HomeController extends Controller
{
private $applicantRepository;
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct(ApplicantsRepository $applicantRepo)
{
$this->middleware('applicant');
$this->applicantsRepository = $applicantRepo;
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('applicant-dashboard.home');
}
public function edit($id)
{
//$applicant = $this->applicantRepository->findWithoutFail($id);
$applicant = Applicant::where('id',$id)->get()->last();
if (empty($applicant)) {
Flash::error('Applicant');
return redirect(route('applicant.home'));
}
return view('applicant-dashboard.edit')->with('applicant', $applicant);
}
public function update($id, UpdateApplicantRequest $request)
{
$applicant = $this->applicantRepository->findWithoutFail($id);
if (empty($applicant)) {
Flash::error('Applicant not found');
return redirect(route('applicant.home'));
}
$input = $request->all();
$applicant = $this->applicantRepository->update([
'name' => $input['name'],
'email' => $input['email'],
'password' => bcrypt($input['password']),
'address' => $input['address'],
'cellphone_no' => $input['cellphone_no']], $id);
Flash::success('Profile updated successfully.');
return redirect(route('applicant.home'));
}
}
Here is the code in my routes:
Route::get('/edit/{id}', 'HomeController#edit')->name('applicant.edit');
Route::patch('/put', 'HomeController#update')->name('applicant.update');
and the code in my blade file:
#section('content')
<section class="content-header">
<h1>
Applicant Profile
</h1>
</section>
<div class="content">
{{-- #include('adminlte-templates::common.errors') --}}
<div class="box box-primary">
<div class="box-body">
<div class="row" style="padding-left: 20px">
{!! Form::model($applicant, ['route' => ['applicant.update', $applicant->id], 'method' => 'patch']) !!}
#include('applicant-dashboard.fields')
{!! Form::close() !!}
</div>
</div>
</div>
</div>
#endsection
I am looking for help.
Thanks in Advance.
Firstly, you use wrong namespace of UpdateApplicantRequest.
Change:
use App\Http\Request\UpdateApplicantRequest;
To:
use App\Http\Requests\UpdateApplicantRequest;
Then, change your form from:
{!! Form::model($applicant, ['route' => ['applicant.update', $applicant->id], 'method' => 'patch']) !!}
#include('applicant-dashboard.fields')
{!! Form::close() !!}
to:
{!! Form::model($applicant, ['route' => ['applicant.update', $applicant->id], 'method' => 'post']) !!}
{!! method_field('patch') !!}
#include('applicant-dashboard.fields')
{!! Form::close() !!}
I have a problem when creating a product, an error message like this appears "ErrorException in Model.php line 2794: Illegal offset type".
enter image description here
Model Product.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = ['name','description','image','size','price','category_id'];
protected $primaryKey = ['product_id'];
public function category()
{
$this->belongsTo(Category::class);
}
}
Model Category.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
protected $fillable = ['title'];
protected $primaryKey = 'category_id';
public function product()
{
return $this->hasMany(Product::class);
}
}
ProductController.php
<?php
namespace App\Http\Controllers;
use App\Product;
use App\Category;
use Laracasts\Flash\Flash;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use File;
use Illuminate\Http\Request;
class ProductController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$q = $request->get('q');
$products = Product::where('name', 'LIKE', '%'.$q.'%')->orderBy('name')->paginate(10);
return view('admin.product.index', compact('products', 'q'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.product.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|unique:products',
'description' => 'required',
'image' => 'mimes:jpeg,png|max:10240',
'size' => 'required',
'price' => 'required|numeric|min:1000'
]);
$data = $request->only('name', 'description', 'size', 'price');
if ($request->hasFile('image')) {
$data['image'] = $this->saveimage($request->file('image'));
}
$product = Product::create($data);
$product->categories()->sync($request->get('category_lists'));
Flash::success('Produk ' .$product->name. ' tersimpan.');
return redirect()->route('backend.products.index');
}
protected function saveimage(UploadedFile $image)
{
$fileName = str_random(40) . '.' . $image->guessClientExtension();
$destinationPath = public_path() . DIRECTORY_SEPARATOR . 'images';
$image->move($destinationPath, $fileName);
return $fileName;
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
create.blade.php
{!! Form::open(['route' => 'backend.products.store', 'files' => true])!!}
<div class="form-group {!! $errors->has('name') ? 'has-error' : '' !!}">
{!! Form::label('name', 'Nama') !!}
{!! Form::text('name', null, ['class'=>'form-control']) !!}
{!! $errors->first('name', '
<p class="help-block">:message</p>
') !!}
</div>
<div class="form-group {!! $errors->has('description') ? 'has-error' : '' !!}">
{!! Form::label('description', 'Deskripsi') !!}
{!! Form::textarea('description', null, ['class'=>'form-control']) !!}
{!! $errors->first('description', '
<p class="help-block">:message</p>
') !!}
</div>
<div class="form-group {!! $errors->has('price') ? 'has-error' : '' !!}">
{!! Form::label('price', 'Harga') !!}
{!! Form::text('price', null, ['class'=>'form-control']) !!}
{!! $errors->first('price', '
<p class="help-block">:message</p>
') !!}
</div>
<div class="form-group {!! $errors->has('size') ? 'has-error' : '' !!}">
{!! Form::label('size', 'Ukuran') !!}
{!! Form::number('size', null, ['class'=>'form-control']) !!}
{!! $errors->first('size', '
<p class="help-block">:message</p>
') !!}
</div>
<div class="form-group {!! $errors->has('category_lists') ? 'has-error' : '' !!}">
{!! Form::label('category_lists', 'Kategori') !!}
{!! Form::select('category_lists[]', [''=>'']+App\Category::lists('title','category_id')->all(), null, ['class'=>'form-control']) !!}
{!! $errors->first('category_lists', '
<p class="help-block">:message</p>
') !!}
</div>
<div class="form-group {!! $errors->has('image') ? 'has-error' : '' !!}">
{!! Form::label('image', 'Gambar') !!}
{!! Form::file('image') !!}
{!! $errors->first('image', '
<p class="help-block">:message</p>
') !!}
#if (isset($model) && $model->image !== '')
<div class="row">
<div class="col-md-6">
<p>Current image:</p>
<div class="thumbnail">
<img src="{{ url('/images/' . $model->image) }}" class="img-rounded">
</div>
</div>
</div>
#endif
</div>
{!! Form::submit(isset($model) ? 'Update' : 'Save', ['class'=>'btn btn-primary']) !!}
{!! Form::close() !!}
Routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
// Front End
Route::get('/', 'CatalogsController#index')->name('index');
// Auth
Route::auth();
Route::get('/home', 'HomeController#index');
// Back End
Route::group(['prefix' => 'backend', 'middleware' => ['auth','admin']], function() {
Route::get('/', function() {
return view('admin.index');
})->name('backend.index');
Route::resource('categories', 'CategoryController');
Route::resource('products', 'ProductController');
});
In your Product Model class, change this line protected $primaryKey = ['product_id']; to protected $primaryKey = 'product_id'; That should resolve this error.
I think because default name changed. make this change and try.
public function category()
{
$this->belongsTo(Category::class, 'category_id', 'category_id');
}
or maybe image isn't set or null, try add this to be:
if ($request->hasFile('image')) {
$data['image'] = $this->saveimage($request->file('image'));
}else{
$data['image'] = '';
}
i get this:
array:7 [▼
"_token" => "dkbgGdfB1wP5rTRlGmKmo0rItrnV5T1pvnj65Uc3"
"name" => "Bukan Hekel"
"description" => "Bukan Hekel"
"price" => "120000"
"size" => "12"
"category_lists" => array:1 [▼
0 => "1"
]
"image" => UploadedFile {#215 ▼
-test: false
-originalName: "bukanhekel.jpeg"
-mimeType: "image/jpeg"
-size: 54465
-error: 0
path: "/tmp"
filename: "phpnjDRJA"
basename: "phpnjDRJA"
pathname: "/tmp/phpnjDRJA"
extension: ""
realPath: false
writable: false
readable: false
executable: false
file: false
dir: false
link: false
}
]
In my ecommerce project, I have Product and Carousel Model.
Product.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $fillable = [
'code', 'name', 'description', 'special_note', 'sort', 'display', 'weight', 'enquiry'
];
public function carousels()
{
return $this->belongsToMany('App\Carousel')->withTimestamps();
}
}
Carousel.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Carousel extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $fillable = ['name', 'display', 'sort'];
public function products()
{
return $this->belongsToMany('App\Product')->withTimestamps();
}
public function getProductListAttribute()
{
return $this->products->lists('id');
}
}
Here's the controller:
public function create()
{
$products = Product::lists('name', 'id');
return view('admin.carousels.create', compact('products'));
}
public function store(Request $request)
{
$carousel = Carousel::create($request->all());
$carousel->products()->attach($request->input('product_list'));
return redirect()->back();
}
public function edit($id)
{
$carousel = Carousel::findOrFail($id);
$products = Product::lists('name', 'id');
return view('admin.carousels.edit', compact('carousel', 'products'));
}
public function update(Request $request)
{
dd($request->all());
}
The carousel form:
<div class="col-md-4 col-sm-4">
<div class="form-group">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control input-sm', 'id' => 'name']) !!}
</div>
</div>
<div class="col-md-4 col-sm-4">
<div class="form-group">
{!! Form::label('sort', 'Sort:') !!}
{!! Form::text('sort', null, ['class' => 'form-control input-sm', 'id' => 'sort']) !!}
</div>
</div>
<div class="col-md-4 col-sm-4">
<div class="form-group">
{!! Form::label('display', 'Display:') !!}
{!! Form::select('display', ['Disabled' => 'Disabled', 'Enabled' => 'Enabled'], null, ['class' => 'form-control input-sm', 'id' => 'display']) !!}
</div>
</div>
<div class="col-md-12 col-sm-12">
<div class="form-group">
{!! Form::label('product_list', 'Products:') !!}
{!! Form::select('product_list[]', $products, null, ['class' => 'form-control input-sm', 'multiple']) !!}
</div>
</div>
<div class="col-md-12 col-sm-12">
<div class="form-group">
{!! Form::submit($submitButtonText, ['class' => 'btn btn-primary btn-block m_top_15', 'id' => $submitButtonId]) !!}
</div>
</div>
Now, the problem is that, when I use form model binding to edit the carousel form, I get no product displayed in the select box, though I can see all the products to select from. The selected products are not seen for the particular carousel.
What is the mistake that I have made ? Kindly help me out.
Thanks.
P.S: I am using Laravel 5.1 and came across this issue for the first time. Earlier I used to do this in Laravel 5 without any issue.
This may be related to how lists() is handled in 5.1. From the upgrade guide -
The lists Method
The lists method now returns a Collection instance instead of a plain
array for Eloquent queries. If you would like to convert the
Collection into a plain array, use the all method:
User::lists('id')->all(); Be aware that the Query Builder lists method
still returns an array.