35 'client_id' => $client->id,
36 'street' => $this->faker->streetName,
37 'number' => $this->faker->buildingNumber,
38 'complement' => $this->faker->secondaryAddress,39 'neighborhood' => $this->faker->citySuffix,
40 'zip_code' => $this->faker->postcode,
41 'city_id' => $city->id,
47 {
48 $serviceOrder = serviceOrder::findOrFail($id);
49 $serviceOrder->update($request->all());
50 return redirect()->route('ticket.edit', $request->ticket_id)->with('success', 'Ordem de serviço atualizada com sucesso!');51 }
52}
33 public function store(Request $request)
34 {
35 ServiceOrder::create($request->all());
36 return redirect()->route('ticket.edit', $request->ticket_id)->with('success', 'Ordem de serviço cadastrada com sucesso!');37 }
38
39 /**
150 */
151 public function updateTeam(Request $request, $sector_id, $user_id)
152 {
153 if (Team::where('sector_id', $sector_id)->where('user_id', $user_id)->update(['admin' => $request->admin])) {154 return response()->json(['success' => true]);
155 }
156 return response()->json(['success' => false]);
45 $occurrence->final_time = $request->final_time;
46 $occurrence->ticket_id = $request->ticket_id;
47 $occurrence->description = $request->description;
48 $occurrence->user_id = $request->user_id;49 $occurrence->save();
50
51 $ticket = Ticket::find($request->ticket_id);
The property you are trying to access is not defined and will cause unexpected behavior when used.
This issue will be raised in the following cases:
__get()
or __set()
magic methods.class Admin
{
public function getName(): string
{
return $this->name; // $name is not declared as a property of the class Admin
}
}
class User
{
private string $name = 'John Doe';
}
class Admin extends User
{
public function getName(): string
{
return $this->name; // $name is a private property of the parent class
}
}
class User
{
protected string $name = 'John Doe';
}
class Admin
{
public function getName(): string
{
$user = new User;
return $user->name; // $name is a protected property defined in the User class, and cannot be accessed outside of it or its descendent classes
}
}
class Admin
{
public string $user = 'John';
public function getName(): string
{
return $this->user->name; // $this->user is not an instance of any class
}
}
Though in this example, the __set()
method is implemented, it doesn't guarantee that properties(username
in this case) being accessed will always be there!
class Admin
{
public function __set(string $name, mixed $value): void
{
$this->{$name} = $value;
}
public function getUsername(): string
{
// invalid: property "username" doesn't exist
return $this->username;
}
}
$admin = new Admin();
// Pay attention to this line. If this line weren't present, the "getUsername" method wouldn't be able to find the "username" property.
$admin->username = 'john';
$admin->getUsername();
class Admin
{
public string $name = 'John Doe';
public function getName(): string
{
return $this->name;
}
}
class User
{
protected string $name = 'John Doe';
}
class Admin extends User
{
public function getName(): string
{
return $this->name;
}
}
class User
{
public string $name = 'John Doe';
}
class Admin
{
public function getName(): string
{
$user = new User;
return $user->name;
}
}
class User
{
public string $name = 'John Doe';
}
class Admin
{
public ?User $user;
public function __construct()
{
$this->user = new User;
}
public function getName(): string
{
return $this->user->name;
}
}
Use @property
PHPDoc tag at the class level to let analyzer know what properties it can access. It'll fix the issue causing this error.
/**
* @property string $username
*/
class Admin
{
public function __set(string $name, mixed $value): void
{
$this->{$name} = $value;
}
public function getUsername(): string
{
return $this->username;
}
}